Javascript 如何在ember中通过指向帮助者的链接获取当前/选定id

Javascript 如何在ember中通过指向帮助者的链接获取当前/选定id,javascript,ember.js,ember-cli,Javascript,Ember.js,Ember Cli,通过这种方式,我可以从代码的任何部分获得router:id值。例如,当链接被激发时,将当前值保存到控制器中 我有一个路由器 this.resource('consultations', function() { this.resource('consultation',{path: '/:id'}); }); 并链接到嵌套路由 {{#link-to 'consultation' item}}-{{/link-to}} 路线咨询 model: function ()

通过这种方式,我可以从代码的任何部分获得router:id值。例如,当链接被激发时,将当前值保存到控制器中

我有一个路由器

this.resource('consultations', function() {
        this.resource('consultation',{path: '/:id'});
    });
并链接到嵌套路由

 {{#link-to 'consultation' item}}-{{/link-to}}
路线咨询

model: function () {return this.store.find('consultation')}
路线咨询

 model: function (consultation) {
        alert(consultation.id); //alert was shown only once, I can't remember current Id
        return this.store.find('consultation',consultation.id);
    },
在这个模型中,我有插座连接,我需要在里面选择id

afterModel: function () {
        socket.on('message', function (message) {
         //here I need to know current consultation ID
        });

}

afterModel接受几个参数,第一个是已解析的模型。这允许您在方法体中从中获取ID:

afterModel: function(resolvedModel) {
  socket.on('message', function (message) {
    var id = resolvedModel.get('id');
  });
}
更多细节可以参考