如何访问Ember.js模型项目通常我不得不这样做是为了获得项目:我没有使用foreach
setupController: function (controller, model) {
this._super(controller, model);
model.accounts.forEach(function (account) {
data.push(account.get("item"));
});
}
相反,我只是想获得这样的第一个项目,但它返回undefined:
model.accounts[0]
Edit__
帐户进来,像这样的路线:
model: function() {
return Ember.RSVP.hash({
main: this.store.createRecord('main', {}),
accounts: this.store.find('account')
});
},
'model.get( '账户')firstObject'应该工作。 – 2014-12-06 17:43:48
当我在我的路由的setupController方法中执行此操作时,未定义 – FutuToad 2014-12-06 17:52:44
那么,您的模型没有'accounts'属性,或者'accounts'属性是空的,至少在您尝试访问它时没有。它应该从哪里来,在什么时候分配给模型,并确定它已经填充?如果“帐户”是异步拥有许多关系,则此时不会自动填充。 – 2014-12-06 17:55:08