【问题标题】:Emberjs CollectionView action on item controller项目控制器上的 Emberjs CollectionView 操作
【发布时间】:2014-04-13 20:14:09
【问题描述】:

我在为集合视图中列出的项目的每个单独项目控制器触发操作时遇到问题。到目前为止,我已经创建了以下内容

App.ItemsController = Ember.ArrayController.extend({
  itemController: 'item',
  sortAscending: true
});

App.ItemController = Ember.ObjectController.extend({
  isDrawVisible: false,
  actions: {
    toggleDraw: function() {
      this.toggleProperty('isDrawVisible')
    }
  }
});

App.ItemsView = Ember.CollectionView.extend({
  itemViewClass: App.ItemView,
  contentBinding: 'controller',
  tagName: 'ul'
});

App.ItemView = Ember.View.extend({
  controllerBinding: 'content',
  templateName: 'item',
  tagName: 'li'
});

而我的模板文件就是这样

{{#with view.content}}
  <a class="btn btn-lg btn-drill left bottom" {{action 'toggleDraw'}}>+</a>
{{/with}}

在 ember 检查器中,列表中的每个项目都被赋予了正确的控制器,但我似乎无法触发 ItemController 上的 toggleDraw 操作

更新:

发现该操作正在被触发,但控制台中出现错误,表明在单击锚元素时没有处理该操作。谁能解释一下?

【问题讨论】:

  • 您的操作哈希中似乎有错字。缺少括号?
  • 谢谢你,我会更新你的问题。我试图从 coffeescript 转换代码,以便更容易阅读。我一定错过了括号。

标签: javascript model-view-controller ember.js


【解决方案1】:

您需要在模板中指定项目控制器,如下所示:

{{#with view.content controller='item'}}
  <a class="btn btn-lg btn-drill left bottom" {{action 'toggleDraw'}}>+</a>
{{/with}}

请参阅with 帮助文档here 中的controller 选项。

【讨论】:

  • 谢谢。我在文档中忽略了这一点。
猜你喜欢
  • 1970-01-01
  • 2013-10-05
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
相关资源
最近更新 更多