2
votes

I have an Ember VeteranRoute set up as below. My Veteran model has name, date, info and medal attributes. I would like to access the veteran's name so I can add it to the title tag, as you can see in the activate function.

I can see that logging out this to the console in the context of the Route reveals the following which contains all the data I would like access to.

Shows console log of "this"

How can I access the name attribute from the data above? I have tried various this.Context._data.name combinations but none seem to work.

app.js VeteranRoute

App.VeteranRoute = Ember.Route.extend({
    model: function(params){
        return this.store.find("veteran", params.veteran_id);
    },
    activate: function() {
        $(document).attr('title',  this.veteran.name);
        console.log(this);
    }
});
1

1 Answers

3
votes

do it in the setupController or afterModel that's when the model has been resolved and is available.

App.VeteranRoute = Ember.Route.extend({
    model: function(params){
        return this.store.find("veteran", params.veteran_id);
    },
    setupController: function(controller, model) {
        this._super(controller, model);
        $(document).attr('title',  model.get('name;));

    }
});