Ember-Data计算属性和defaultValue

时间:2014-05-20 23:19:42

标签: ember.js ember-data

我在ember-data中有一个模型定义为:

App.Note = DS.Model.extend({
  content: attribute('string'),
  createdDate: attribute('string', {
    defaultValue: function() {return new Date()}
  }),
  title: function() {
    // do stuff
  }.property('content', 'createdDate') 
});

我注意到当我用:

创建一个新对象时
this.store.createRecord('note');

不计算title属性。我假设默认值会触发属性更新,但事实并非如此。如何获取默认值以触发计算属性以触发?

1 个答案:

答案 0 :(得分:2)

我认为问题在于您使用'content'作为属性名称。我会避免使用这个词,因为Ember倾向于自己使用它并且它可以搞砸了。这是你的代码的jsbin:http://emberjs.jsbin.com/jebugofo/6/edit?html,css,js,output。只需要摆脱该物业的名称。

相关问题