我有以下代码,我试图为其设置模型,ApplicationRoute
但它似乎不起作用。我对 Ember 代码有一些疑问。首先,我可以为申请路线设置一个模型吗?其次,如果路由模型具有名为 count 和 fileName 的字段,我是否还需要在控制器中声明这些字段。看起来如果我这样做,控制器中的值优先于模型值。即使在任何地方都没有定义总数 ,我也可以做类似this.set('total',5)
的事情。setupController
App.ApplicationRoute=Ember.Route.extend({
model:function(){
console.log('model called');
return {count:3,fileName:'Doc1'};
},
setupController:function(){
console.log(this.get('model').fileName);
this.set('count',this.get('model.count')); //Do I manually need to do this?
this.set('fileName',this.get('model.fileName')); //Do I manually need to do this?
}
});
App.ApplicationController=Ember.Controller.extend({
count:0,//Is this necessary?? Can I directly set the property with declaring it like this
fileName:''
});