XDQ的笔记本

ember

A 2 post collection


让部分ember-data属性不保存到服务器

 •  Filed under ember

在ApplicationSerializer中添加

App.ApplicationSerializer = DS.RESTSerializer.extend({
  serializeAttribute: function(record, json, key, attribute) {
    if (!attribute.options.readOnly) {
      return this._super(record, json, key, attribute);
    }
  }
});

然后再其他model中就可以

App.User = DS.Model.create({
  admin: DS.attr('boolean', { readOnly: true })
})

ember 在加载页面后执行js方法

 •  Filed under ember

在合适的地方加入一下代码

Ember.run.scheduleOnce('afterRender', this, afterRenderEvent);
afterRenderEvent : function(){
	// implement this hook in your own subclasses and run your jQuery logic 		there
}

可以加在model上

也可以加在view上

App.YourView = Ember.View.extend({
    didInsertElement : function(){
        this._super();
        Ember.run.scheduleOnce('afterRender', this, function(){
            // perform your jQuery logic here
        });
    }
});

也可以重写view对象(对所有view有效)

Ember.View.reopen({
      didInsertElement : function(){
          this._super();
          Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
      },
      afterRenderEvent : function(){
          // implement this hook in your own subclasses and run your jQuery logic there
      }
});