[英]Ember.js: How to create route/controller with single instance of a model
[英]How do i drill into any model from the store inside a controller or a route in 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')
});
无论如何,一旦实现承诺,我就会在商店中存储数据。我的问题是,如何从中提取用户?
这是我从promise函数得到的类。
用户数组u可以在底部看到。 但是我如何从promise回调中到达那里呢? 抱歉,如果我的问题很傻,但我仍然是新手。
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
});
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.