如何从使用车把助手的视图中调用控制器内部的操作(不确定车把助手是否与获取控制器相关,但无论如何我都想提一下(?
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:
我在click:function(){}
中添加了this.get('controller').send('controllerActionName');
,我收到错误Uncaught TypeError: undefined is not a function
在那行代码上。
如果我将this.get('controller').send('controllerActionName');
添加到didInsertElement:function((,我根本没有收到任何错误。
编辑 2:
车把帮助程序位于使用名为 recordType
的对象控制器的列表中。"recordType"是我希望从车把帮助的单击事件调用的操作。然而
在record_types.HBS
{{#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
。
要从控制器的视图调用控制器操作,请执行以下操作:
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');
}
});