如何從使用手柄助手的視圖調用控制器內的動作(不確定手柄助手是否與獲取控制器相關,但我想提及它無論如何)?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