【发布时间】:2015-08-10 00:16:56
【问题描述】:
CRUD 中的每一行都有一个 item-row.js 组件和一个触发“addNewItem”的按钮,因为我需要做一些额外的处理。
好吧,动作永远不会冒泡到路线,所以我相信我做错了什么。 Ember 指南会告诉我做我正在做的事情,所以我完全迷失在这里。我错过了什么吗?
代码:
我的模板是这样的:
// my-template.hbs
{{#each model as |item|}}
{{#item-row
id = item.id
text = item.text
}}
{{item.title}}
{{/item-row}}
{{/each}}
在该组件的模板中:
// item-row.hbs
// a couple of HTML here
<button {{action "addNewItem"}}> </button>
当然,我有一个组件
// item-row.js
export default Ember.Component.extend({
actions: {
addNewItem: function(){
this.sendAction('addNewItem');
// already tried this.sendAction() without the parameter..
return true;
}
}
});
最后,我的路线:
// item.js
export default Ember.Route.extend({
actions: {
addNewItem: function(){
alert('reached the route!!!!!');
// this is never printed =/
}
}
});
感谢您的帮助:)
【问题讨论】:
-
这让我每次都兴奋!
标签: javascript ember.js