简体   繁体   中英

Ember.js - Access model attributes from activate function within Route

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.

显示“此”的控制台日志

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);
    }
});

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;));

    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM