Javascript 如何在ember.js中从控制器或路由中的商店钻取任何模型?
我在我的路线内有我的承诺功能Javascript 如何在ember.js中从控制器或路由中的商店钻取任何模型?,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我在我的路线内有我的承诺功能 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) { controlle
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函数得到的类
请参阅
你可以在底部看到用户阵列。但是我怎样才能从承诺回拨中到达那里呢?
抱歉,如果我的问题很傻,但我对ember还是新手。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
});
});
}