如何从控制器内的商店或ember.js中的路径钻取任何模型?
问题描述:
我有我的诺言功能我的路线内的如何从控制器内的商店或ember.js中的路径钻取任何模型?
setupController: function (controller,model) {
// Set the IndexController's `title`
this.controllerFor('New').set('model', model);
this.store.find('selectFill', { x: "20", y: "30" }).then(function (data) {
controller.set('selectFill',data.?????);
});
}
我的模型看起来像这样,
App.SelectFill = DS.Model.extend({
users: DS.hasMany('user', {
embedded: true
})
});
App.User = DS.Model.extend({
userId:DS.attr('string'),
department: DS.attr('string')
});
反正一旦承诺撞到,我在store.My问题是数据,我如何从中提取用户?
这里是我从promise函数获得的类。
用户排列U可以在底部看到。但我如何从承诺回调那里得到? 对不起,如果我的问题很愚蠢,但我仍然是新的烬。
答
this.store.find('selectFill', { x: "20", y: "30" })
将解析类似于对象的数组(DS.AdapterPopulatedRecordArray
),该示例中的变量为selectFills
。因为它是一种数组,所以您可以使用forEach遍历每个selectFill,并让用户调用selectFill.get('users')
。像这样:
setupController: function (controller,model) {
// Set the IndexController's `title`
this.controllerFor('New').set('model', model);
this.store.find('selectFill', { x: "20", y: "30" }).then(function (selectFills) {
selectFills.forEach(function(selectFill) {
var users = selectFill.get('users');
// do something with the users
});
});
}