vendredi 23 janvier 2015

Why can't I display the second association in a nested each loop?

I have 2 models deliverHour and day. In an .hbs file, I have two nested each loops.


I am trying to display the delivery hours for each day. Apparently, once it reaches the second each loop, it doesnt render anything. Not even this line does not render!


Looking in Ember Inspector. I do not see any failed promises. The network tab doesn't even show Ember trying to attempt calling the delivery hour end point. The Data tab shows delivery-hour (0), which means no delivery hours in the store, which is strange.


Since the relationship for the day model has DS.hasMany('deliveryHour', { async: true }) I would have expected Ember to do an asynchronous call to the delivery hour api resource. No?


What am I missing here?



// Route
import Ember from 'ember';

export default Ember.Route.extend({
model: function(params) {
var addressId = this.checkoutCart.get('addressId');

return Ember.RSVP.hash({
address: this.store.find('address', addressId),
delivery: this.store.createRecord('delivery'),
days: this.store.find('day')
});
},

// You can use model.delivery to get delivery, etc
// Since the model is a plain object you can just use setProperties
// http://ift.tt/1hAAP0e
setupController: function(controller, model) {
controller.setProperties(model);
},
});

// app/models/delivery-hour.js
import DS from 'ember-data';

export default DS.Model.extend({
day: DS.belongsTo('day', { async: true }),
from: DS.belongsTo('hour', { async: true }),
to: DS.belongsTo('hour', { async: true }),
status: DS.attr('string')
});

// app/models/day.js
import DS from 'ember-data';

export default DS.Model.extend({
deliveryHours: DS.hasMany('deliveryHour', { async: true }),
name: DS.attr('string'),
dayOfTheWeek: DS.attr('number')
});

// hbs
{{#each day in days}}
<li>
{{day.name}} // Returns something like 'Monday'
{{day.deliveryHours}} // Returns something like <(subclass of DS.PromiseArray):ember770>

{{#each deliveryHour in day.deliveryHours}}
this line does not render!
{{deliveryHour.hour}} <----- ideally, this is what i want to see
{{/each}}
</li>
{{/each}}




Aucun commentaire:

Enregistrer un commentaire