【发布时间】:2014-12-04 18:20:39
【问题描述】:
如何从使用车把助手的视图中调用控制器内部的动作(不确定车把助手是否与获取控制器相关,但我还是想提一下)?
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”是我希望从车把帮助的点击事件中调用的那个动作。不过
在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。
【问题讨论】:
标签: javascript model-view-controller ember.js handlebars.js