如何从使用手柄助手的视图调用控制器内的动作(不确定手柄助手是否与获取控制器相关,但我想提及它无论如何)?Handlebar.helper的视图不能使用来自控制器的动作
VpcYeoman.EditRecordCategoryView = Ember.TextField.extend({
//This is where i call the action from any controller
click: function() { // might be a property or some other action
this.get('controller').send('controllerActionName');
}
});
Ember.Handlebars.helper('edit-recordCategory', VpcYeoman.EditRecordCategoryView);
我会在该视图内部做些什么来告诉控制器我希望它激活其操作之一?
编辑1:
我添加this.get('controller').send('controllerActionName');
到click:function(){}
, 和我接收该行上的码的错误Uncaught TypeError: undefined is not a function
。
如果我将this.get('controller').send('controllerActionName');
添加到didInsertElement:function(),我根本没有得到任何错误。
编辑2:
车把辅助位于该使用名为recordType
对象控制器的列表。 'recordType'是我正在寻求从车把帮助的点击事件调用的动作。然而
{{#each itemController="recordType"}}
{{#unless isEditing}}
{{categoryName}}
{{/unless}}
{{#if isEditing}}
{{edit-recordCategory class="edit" value=category_name focus-out="acceptChanges" insert-newline="acceptChanges"}} //This is the handlebar helper
{{/if}}
{{/each}}
我们可以假设,在记录中的isEditing
属性是true
因为车把助手将是不可见的,如果它是false
。
其实我的项目的控制器中的动作是为了切换该属性isEditing
。
IM接收到错误'遗漏的类型错误:未定义是不是该长function'。它有可能不知道里面的控制器是什么? – 2014-12-04 19:08:18
不是真的,视图总是会有一个控制器,因为它们默认呈现它们的上下文。你如何渲染?你的模板是什么样的? – givanse 2014-12-04 20:20:29
好吧,因为对象控制器设置在'{{#each}}'循环中(也是我想要的那个动作所在的位置)。我更新了你的问题(编辑2) – 2014-12-04 20:54:07