嗨,我是非常新的ember js.我在模板中的链接到动作上传递动作参数(id)但我没有在我的控制器中获取值.
我的模板代码如下:
index.html的:
<script type="text/x-handlebars" data-template-name="search">
{{#each model.results}}
// here i pass id value along with action
{{#link-to 'profile' id action="profileinfo"}}
</script>
Run Code Online (Sandbox Code Playgroud)
app.js:
App.SearchController = Ember.ObjectController.extend({
id: '',
actions:{
profileinfo: function(id){
// Here i access id value like this
console.log(id);
var id = this.get('id');})
Run Code Online (Sandbox Code Playgroud)
当我点击链接动作转到Searchcontroller,但我得到id值为空.我在堆栈溢出中遵循一些解决方案,但不幸的是我没有得到任何东西.请提供一些解决方案
我不明白为什么你使用{{#link-to}}助手来触发控制器上的动作.也许你可以简单地使用{{action}}帮手?
如果你尝试这样做,它会起作用吗?
<button type="button" {{action "profileinfo" id}}>Click me !</button>
Run Code Online (Sandbox Code Playgroud)
从那里,你console.log(id);应该得到你的价值.
编辑
也适用于<a>标签
<a href="#" {{action "profileinfo" id}}>Click me !</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4489 次 |
| 最近记录: |