Ember.js 余烬数据计算属性和默认值
我在余烬数据中有一个模型定义为:Ember.js 余烬数据计算属性和默认值,ember.js,ember-data,Ember.js,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') })
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属性。我假设默认值会触发属性更新,但事实并非如此。如何获取默认值来触发计算属性?我认为问题在于您正在使用“内容”作为属性名称。我会避免使用这个词,因为余烬本身经常使用它,它会把事情搞砸。以下是您的代码工作的jsbin:。只是需要去掉属性的名称。也许你是对的,但我返回了“内容”,输出看起来是一样的