itemController上的Ember操作无法正常工作

时间:2014-09-08 06:05:23

标签: ember.js handlebars.js

这是我的控制器:

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}},包含和不包含引号

没有任何作用。

有谁可以指出我做错了什么?

1 个答案:

答案 0 :(得分:0)

此行为的一个可能原因是a bug present in 1.13 (up until the very last 1.x release, 1.13.13),它会中断应由项目控制器处理的操作。

如果您无法恢复发布1.12,那么问题的第二个解决方法

  

将{{#each}}更改为{{控件中的#each项}}并将target=item添加到操作中

是官方推荐的,并且已经为我的代码工作了,虽然第一个

  

将<{1}}添加到操作(使用简单{{#each}})

应该也可以。

(我怀疑OP在代码中留下了其中任何一个,并没有注册它解决了问题,因为早先由于Firefox的非常持久的缓存而出现了假阴性。)

相关问题