如何获取当前/选定的id与链接到成员中的助手
How to get current/selected id with link-to helper in ember
通过这种方式,我可以从代码的任何部分获得路由器: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文档中找到。
相关文章:
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 如何进行AJAX调用,使其仅在我单击包含在特定类中的链接时触发;id”;父元素的
- 通过单击链接(兄弟姐妹?)从无线电输入中获取id
- 通过id查找元素并附加链接
- url中没有id的内部链接
- 如何绑定多个具有相同敲除功能、传递不同ID的链接
- 修复Javascript代码以将文本中的所有Youtube链接转换为Youtube ID功能
- 如何从链接中检索 ID
- 使用 JS 捕获链接 ID,然后定向到链接
- 如何在另一个html文件中获取超链接ID
- jQuery编辑链接id
- 链接id使用jquery传递值到表单
- 使用javascript替换基于查询字符串的自定义链接id
- 基于它's调用超链接id定制弹出窗口
- 文档.getElementById用于链接id
- 从jQuery选项卡搜索脚本中删除链接ID元素
- 从jQuery选项卡脚本的链接ID中删除元素
- 简单的JavaScript将数组链接ID附加到html文档中
- 提取要在 jquery 函数中使用的链接 ID
- 使用javascript获取被点击的html链接id