0
votes

[I'm on Ember 1.0.0 - Ember.data 0.13]

In a nested route I'm using the setupController hook in order to load a list of templates which I use as selection list for my model, a Offer object:

controller.set('offerTemplates', App.OfferTemplate.find());

Complete code:

App.OfferEditRoute = Ember.Route.extend({
    model: function () {
        return this.modelFor("offer");
    },
    setupController: function (controller, model) {
        controller.set('content', model);
        controller.set('offerTemplates', App.OfferTemplate.find());
    },
    renderTemplate: function () {
        this.render('offer-edit-title', { into: 'application', outlet: 'page-title', controller: 'offerEdit' });
        this.render('offer-edit', { into: 'application', controller: "offerEdit" }); //
    }
});

App.OfferEditController = Ember.ObjectController.extend({
    offerTemplates: [],
    ...
)};

This used to work until Ember 1 RC 7, but doesn't in 1.0.0. The main content of the Offer (model) is correctly rendered, but the template list bound to the controller's offerTemplates property (array) is not rendered on loading the page (browser page refresh).

If I switch page and back to the route, all is rendered correctly.

Any hint?

1
Oops, that's just a copy paste mistake I made copying from two similar files. It's the OfferEditController. Sorry! I've updated the post.splattne
which version of Ember Data are you using? Beta 1?colymba
@colymba No still on Ember.data 0.13splattne
Have you checked wether the property is actually populated? Try App.__container__.lookup("controller:offerEdit").get("offerTemplates.length")mavilein
@mavilein yes, it's fetched from the server's API and populated. Result: 12 (which is the correct number of offerTemplates)splattne

1 Answers

0
votes

The problem was related to the template which doesn't use the offerTemplates array but a computed property offerTemplatesByGuestUserLanguage:

{{#each offerTemplate in offerTemplatesByGuestUserLanguage}}
    ...
{{/each}}

I forgot the second to add the second property content.guestUser.language in the computed property of the controller:

offerTemplatesByGuestUserLanguage: function() {
    var templates = this.get("offerTemplates"),
        guestUserLanguageCode = this.get("content.guestUser.language.code");

    return templates.filter(function (item) {
        return item.get("language.code") === guestUserLanguageCode;
    });
}.property('offerTemplates.@each', 'content.guestUser.language')

I wonder why it even worked in RC.7.