admin管理员组文章数量:1424993
I have the following problem in ember.js. A child controller depends on a selected value in a parent controller in order to determine its content. In the database a child has a parent_id reference.
App.parentsController = Em.ArrayController.create({
content: [],
selected: null
});
App.sonsController = Em.ArrayController.create({
// the value of content depends on the id of
// the selected item in the parentsController
content: [],
selected: null
});
App.daughtersController = Em.ArrayController.create({
// the value of content depends on the id of
// the selected item in the parentsController
content: [],
selected: null
});
I would prefer to solve this without the parentsController having to know anything about the other controllers. This should be possible with observers, bindings or even through calculations but I have no clue where to start. Any help would be well appreciated.
I have the following problem in ember.js. A child controller depends on a selected value in a parent controller in order to determine its content. In the database a child has a parent_id reference.
App.parentsController = Em.ArrayController.create({
content: [],
selected: null
});
App.sonsController = Em.ArrayController.create({
// the value of content depends on the id of
// the selected item in the parentsController
content: [],
selected: null
});
App.daughtersController = Em.ArrayController.create({
// the value of content depends on the id of
// the selected item in the parentsController
content: [],
selected: null
});
I would prefer to solve this without the parentsController having to know anything about the other controllers. This should be possible with observers, bindings or even through calculations but I have no clue where to start. Any help would be well appreciated.
Share Improve this question asked Jun 6, 2012 at 15:51 codehuggercodehugger 6396 silver badges16 bronze badges1 Answer
Reset to default 6You can use the binding system. The sonsController
needs to observe the parentsController.selected
property, and then update its content.
Here is an example of how you can do that :
App.parentsController = Em.ArrayController.create({
content: [],
selected: null
});
App.sonsController = Em.ArrayController.create({
parentControllerBinding: 'App.parentsController',
content: [],
updateContent: function() {
var selected = this.getPath('parentController.selected');
var newContent = Ember.A();
newContent.pushObject(selected);
this.set('content', newContent);
}.observes('parentController.selected')
});
And here is the jsfiddle associated.
N.B. : you could also directly bind the selected property :
App.sonsController = Em.ArrayController.create({
parentSelectedBinding: 'App.parentsController.selected',
...
updateContent: function() {
...
}.observes('parentSelected')
})
本文标签:
版权声明:本文标题:javascript - How to update content of one ArrayController from the selected value of another ArrayController in Ember.js - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745421109a2657903.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论