【发布时间】: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