![](/img/trans.png)
[英]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.