I have my promise function inside my route as
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.?????);
});
}
my model looks like this,
App.SelectFill = DS.Model.extend({
users: DS.hasMany('user', {
embedded: true
})
});
App.User = DS.Model.extend({
userId:DS.attr('string'),
department: DS.attr('string')
});
anyway once the promise get hit, i have the data in the store.My question is, how do i extract the users from it?
here is the class i get from the promise function.
Please refer to this image here.
Users array u can see on the bottom. but how do i get there from the promise callback? sorry if my question is silly, but i'm still new to ember.
this.store.find('selectFill', { x: "20", y: "30" })
will resolve a array like object ( DS.AdapterPopulatedRecordArray
), in that sample is the selectFills
variable. Because it's a kind of array, you can use forEach to iterate in each selectFill and get the user calling selectFill.get('users')
. Like this:
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
});
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.