如果我在控制器中执行此操作,则会分配addressList属性。
addressList : function () {
model.accounts.forEach(function (account) {
addressList.push(account.get("address"));
});
return addressList;
}.property(),
但是如果我在路线中的afterModel挂钩中做同样的事情:
model.accounts.forEach(function (account) {
addressList.push(account.get("address"));
}
});
this.controllerFor("journey").set("addressList", addressList);
我收到错误:
Error while processing route: journey Assertion Failed: Cannot delegate set(.. to the 'content' property of object proxy .. its 'content' is undefined.
答案 0 :(得分:1)
此处没有错误或错误。您不应该从路由设置控制器属性。您的第一个实施是正确的做事方式。
关于afterModel
挂钩
适合执行只能在模型解析后才能进行的逻辑
http://emberjs.com/api/classes/Ember.Route.html#method_afterModel
您在控制器中定义的任何属性也将在模型解析后设置 。所以从这个角度来看,它的工作原理是一样的。
afterModel
钩子的用例是当逻辑“失败”时,你需要重定向到另一条路线。
控制器是模型装饰器,您可以在其中设置从模型数据派生的属性。