【发布时间】:2014-09-08 06:05:22
【问题描述】:
这是我的控制器:
App.DesignPhotosController = Ember.ArrayController.extend({
itemController: 'designPhoto'
});
App.DesignPhotoController = Ember.ObjectController.extend({
needs: ['designPhotos'],
toDelete: false,
actions: {
toggleDelete: function() {
this.set('toDelete', !this.get('toDelete'));
}
}
});
还有我的模板:
{{#each}}
<ul>
<li>
{{title}}
{{#if toDelete}}
<button class="restore" {{action "toggleDelete"}}>Restore</button>
{{else}}
<button class="delete" {{action "toggleDelete"}}>Delete</button>
{{/if}}
</li>
</ul>
{{/each}}
但是,当我单击“删除”按钮时,我会收到一条消息:
Error: Nothing handled the action 'toggleDelete'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.
据我所知,我这样做是正确的,我尝试通过以下各种组合来强制它:
将
target=this添加到操作中添加 {{#each item in controller}} 和
target=item将操作更改为 {{action toggleDelete this}},带引号和不带引号
没有任何作用。
谁能指出我做错了什么?
【问题讨论】:
-
似乎在这里工作emberjs.jsbin.com/xedol/1。代码看起来也不错,唯一可能发生的是模板的上下文控制器可能不是“designPhotos”(您可以在每个控制器之外记录控制器并检查是否是这种情况或不使用 {{log controller}} )
-
神秘 - 刚刚再次打开我的代码尝试记录它,现在它可以工作了!也许是 Firefox 缓存中搞砸了。