1
votes

I have a model hook in my Route object that looks like this:

model: function(params) {
    // return an active filter for activities on given date
    return this.store.filter('activity',function(activity){     
        var itemDate = new Date(activity.get('start_time'));
        itemDate = moment(itemDate).format('YYYY-MM-DD');
        return itemDate === params.on_date;
    });
}

The route's currentModel gets populated with the DS.FilteredRecordArray with all the appropriate values set but for some reason the model never gets passed to the controller and therefore my template's {{#each}} {{/each}} remains empty.

I created a hack where I set added the following to the route:

setupController: function(controller, model) {
    controller.set('model',this.get('currentModel'));
}

This actually works when you load the controller the first time but then goes into an infinite loop when you transitionTo to the route. Ahh well, it was a hack anyway. Does anyone know how I can get this working the "Ember way"?

1
Could you post the code where you set currentModel? - chopper
I never actually set currentModel explicitly. I just assumed this was part of the Ember dark arts. I simply return an object from the model hook in the Route and currentModel gets populated (with what I'd expect to be in the model property. - ken
I have never heard of that myself, maybe it's an internal thing? In any case I'm not sure why you would need that since the model is passed into the setupController function as a parameter. Thus all you should need to do is controller.set('content', model);. I'll also add that as an answer - let me know if that works for you. - chopper

1 Answers

2
votes

You will need to populate the content of your controller with your model (the result of your filter function) like this:

setupController: function(controller, model) {
    controller.set('content', model);
}

Though this should also be the default behavior and I don't think you need to explicitly define that.