我有一個名爲tickets
路線這有它的像這樣無法調用foreach所模型散列控制器
model() {
return Ember.RSVP.hash({
event: null,
tickets: null
});
},
actions: {
didTransition(){
if(!this.controller.get('model.length')){
new Ember.RSVP.hash({
event: this.modelFor('events.event'),
tickets: this.store.query('ticket',{user_id:this.get('user.user.user_id'),event_code:this.modelFor('events.event').get('event_code')})
}).then((hash)=>{
if(!hash.tickets.get('length')){
this.controller.set('noTickets',true);
}
this.controller.set('model',hash);
});
}
}
}
模板對這些model.tickets
只是在一個{{#each}}
塊精細管理,以循環模式設置
在我的控制,我試圖安裝一個groupBy
計算的,但在我的計算是從哪裏獲得的錯誤
ticketsByPurchase: Ember.computed('model.tickets.[].ticket_purchase_code',function(){
let tickets = this.get('model.tickets');
tickets.forEach(function(ticket){
console.log(ticket);
});
})
你可能會想用'@ each',而不是'[]'你相依性。 'model.tickets。@ each.ticket_purchase_code' – Kingpin2k