我有一条名为的路线tickets
,其模型设置如下
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);
});
})