我很难让这个基本功能在Ember中工作。如何通过正在观察通过另一个Ember.Select设置的另一个属性的计算属性填充Ember.Select视图的选项?
以下是我迄今所做的工作:
HTML/HBS:
<script type="text/x-handlebars">
{{view Ember.Select
content=parent
optionValuePath="content.id"
optionLabelPath="content.name"
value=current_parent}}
{{view Ember.Select
content=child
value=current_child}}
</script>Javascript:
App.ApplicationController = Ember.ArrayController.extend({
content: '', current_parent: null, current_child: null,
parent: function() {
return this.store.find('user');
}.property(),
child: function() {
var current_parent = this.get('current_parent');
if (current_parent) {
this.store.find('user', current_parent).then(function(parent) {
return parent.get('children');
}
}
}.property('current_parent')
});
App.User = DS.Model.extend({
name: DS.attr('string'),
children: DS.attr(),
});从服务器返回的JSON:
users: [{id: 0, name: 'test', children: ['child1', 'child2']}]显然这是行不通的。我很想解释一下我在这里做错了什么,有什么可行的方法来实现这一点,请。
我使用的是以下语言:
提前感谢!
发布于 2014-02-23 04:15:51
我觉得你不需要衍生财产的孩子。不使用id作为值,您可以使用模型本身(用户),它已经具有children的属性。这与您已经使用current_parent而不是current_parent_id的名称相匹配。
{{view Ember.Select
contentBinding=parent
optionLabelPath="content.name"
value=current_parent}}
{{view Ember.Select
contentBinding=current_parent.children
value=current_child}}在控制器上,只需移除子属性。
希望这能有所帮助。
https://stackoverflow.com/questions/21959335
复制相似问题