如何获取当前/选定的id与链接到成员中的助手

How to get current/selected id with link-to helper in ember

本文关键字:链接 id 成员 何获取 获取      更新时间:2023-09-26

通过这种方式,我可以从代码的任何部分获得路由器: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);
    },

在协商afterModel时,我有套接字连接,我需要在内选择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');
  });
}

更多细节可以在Ember文档中找到。