setupController hook block loading data model hook


#1

Hi sorry if the question has already send. I have a problem with setupController hook. I don’t know if I use it correctly or if I make a mistake.

My route methode :

BNNP.IndexRoute = Ember.Route.extend({
    model: function() {
        return BNNP.Info.find();
    },

    setupController: function() {
        this.controllerFor('photosIndex').set('model', BNNP.Photo.find({valid: true}));
    }
});

My template :

<script type="text/x-handlebars" id="index">
    {{#view BNNP.NewsView}}
    <h3 title="Cliquer pour voir les dernières news" style="cursor:pointer" {{action showNews target="view"}}>Dernières
    News</h3>
    <div id="news" class="row-fluid">
        {{#each info in controller}}
        <b>{{info.title}}</b> : {{{info.text}}}<br>
        {{else}}
        <i>Chargement en cours</i>
        {{/each}}
    </div>
    {{/view}}
    <div class="row-fluid">
        {{render photos/index}}
    </div>
</script>

<script type="text/x-handlebars" id="photos/index">
    <ul class="thumbnails">
        {{#each photo in controller}}
            <li class="span2">
                <div>
                    {{#linkTo photos.byId photo}}<h5 {{action incrementShow}} >{{photo.imageTitle}}</h5>{{/linkTo}}
                    {{#linkTo photos.byId photo class="thumbnail"}}
                    <img {{bindAttr src="photo.imageUrl"}} />
                    {{/linkTo}}
                    Publiée par : {{photo.author.name}}<br>
                    Vu {{photo.nbView}} fois. 0 commentaire<br>
                </div>
            </li>
        {{ else }}
            <p>Il n'y a pas de photo</p>
        {{/each}}
    </ul>
</script>

The request BNNP.Photo.find return an empty response => [].

When I comment setupController hook, info data are properly load and transmitted to my template. In this case everything works but when I uncomment setupController hook info data are not load or not visible in my template.

When I provide data to photos, photo data are load but always nothing for info data

Is this the right way to load info data and photo data in the same route or in otherwise how I do ?

Thanks a lot in advance for your futur help !


#2

If I understand you correctly your problem is that the Info data is not set on the controller when you use your own setupController method, right?

That is, because you have to fulfill the original task of this method, too. That would be:

setupController: function(controller, model) {
    // care about own model first
    controller.set('content', model);
    // then do additional setup
    this.controllerFor('photosIndex').set('model', BNNP.Photo.find({valid: true}));
}

The default implementation does exactly the first action, which you left out in your own. You can also call this._super(controller, model) instead, but this should make no difference.

This behavior was changed in http://emberjs.com/blog/2013/05/28/ember-1-0-rc4.html


#3

Ok thanks for your explications it’s works and know I understand my mistake :smiley: