嗨,我想知道什麼是正確的方式來更新路由組件上的屬性?Emberjs如何從路由更新組件的屬性?
什麼我想要做一點背景:
我有我叫CardButtons兩個自定義按鈕(根據材料德興)旁邊的一個名爲描述的空白區,我要的是創造一個懸停事件觸發ajax調用來從數據庫中檢索詳細數據並將其呈現在描述區域中。
檢查更新
到目前爲止,我已經創造了這樣的路線:
export default Ember.Route.extend({
selectedModule: '',
model: function() {
return {
selectedModule: 'employeeModule'
};
},
actions: {
showDescription: function (params) {
this.set('model.selectedModule', params);
}
}});
我的路徑模板調用我的組件是這樣的:
<div class="row">
{{sis-db-description-render idTitle=model.selectedModule}}
</div>
和組件定義像這樣:
export default Ember.Component.extend({
info: null,
ready: false,
didInsertElement: function() {
this.queryData();
},
queryData: function(){
/** Does an Ember.$.post request to the API with the idTitle as param**/
}
});
這是第一次執行它完全加載細節數據,但是當我嘗試刷新數據時事件不會觸發第二個調用。我非常敬重,因爲我沒有以適當的方式更新模型。
關於如何更新組件屬性的任何想法?
UPDATE:
感謝@kumkanillam我能找到我的路線上一種方法,我添加了下面的代碼:
setupController: function (controller, model) {
this._super(...arguments); //if its new/index.js route file then you can use controller argument this method.
controller.set('selectedModule', 'employeeModule');
},
actions: {
showDescription: function (params) {
console.info(params);
this.controllerFor('new.index').set('selectedModule', params);
}
}
通過這樣做,現在認爲每次更新內容,我仍然不知道這是否是正確的方式,但它現在可行。
'didInsertElement'將被稱爲初次單獨渲染。 – kumkanillam
我需要什麼方法來更新?據我瞭解,如果我更新組件路線上的porperty組件應該重新渲染並調用didUpdateAttrs方法,但不是這種情況didUpdateAttrs永遠不會被調用。 – DeividKamui
其實你不更新。在路線'this.set('model.selectedModule',params);'這裏模型是未定義的。它在控制器中定義。 – kumkanillam