[英]Ember RSVP Hash not updating controller content
I am trying to have handle multiple controllers at one route in Ember. 我正在尝试在Ember的一条路由中处理多个控制器。 This response seems like the way to go, but am having difficult getting this to work.
这种回应似乎是行之有效的方法,但是很难使它起作用。 Here is a simple example that fails to work:
这是一个无法正常工作的简单示例:
App.IndexRoute = Ember.Route.extend({
model: function() {
myData = [1,2,3];
return Em.RSVP.hash({
docs1: myData,
docs2: myData
});
},
setupController: function(controller, model) {
controller.set('model', model.docs1);
this.controllerFor('documents').set('model', model.docs2);
}
});
App.DocumentsController = Ember.ArrayController.extend({
count: function() {
return this.get('length');
}.property('@each'),
});
App.IndexController = Em.ArrayController.extend({
count: function() {
return this.get('length');
}.property('@each'),
});
And a JSBin showing the results: 还有一个显示结果的JSBin:
http://jsbin.com/wavigada/1/edit http://jsbin.com/wavigada/1/edit
You can see that the IndexController reports the correct count of 3, but the DocumentsController doesn't get set. 您可以看到IndexController报告正确的计数为3,但是没有设置DocumentsController。
Can anyone help me out? 谁能帮我吗?
You will need to include the documents
controller whose content you populate in setupController
in your IndexController
via needs
: 您将需要包括
documents
控制器,其内容您在填充setupController
在你IndexController
通过needs
:
App.IndexController = Em.ArrayController.extend({
needs: ['documents'],
count: function() {
return this.get('length');
}.property('@each'),
});
Then you need to change your template to: 然后,您需要将模板更改为:
<script type="text/x-handlebars" data-template-name="index">
{{count}}
{{render 'documents' controllers.documents}}
</script>
Note that just putting {{render 'documents' controllers.documents}}
(as you did in your question) refers to a documents
property of your current model, which doesn't exists. 请注意,仅放置
{{render 'documents' controllers.documents}}
(就像您在问题中所做的那样)是指当前模型的documents
属性,该属性不存在。
See: http://jsbin.com/wavigada/6/ 请参阅: http : //jsbin.com/wavigada/6/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.