有這個帖子:「What's the right way of doing manual form data saving with Ember.js?」,但是,我對如何用Ember 2.3做到這一點感到不知所措。在Ember.JS中保存表格數據 - 使用版本2.3
在accepted answer這個問題,我們有這樣的片段:
App.IndexController = Ember.ObjectController.extend({
proxy: {},
setUnknownProperty: function(key, value) {
console.log("Set the unknown property: " + key + " to: " + value);
this.proxy[key] = value;
console.log(this.proxy);
},
flush: function() {
for(var key in this.proxy)
this.set('model.'+key, this.proxy[key]);
}
});
然而,我沒有一個「ObjectController」在我的項目。運行
ember generate controller test
給我的東西,上面寫着Ember.Controller.extend({ ... });
,而不是ObjectController。搜索2.3 API,我根本找不到ObjectController。
將代碼片段插入Ember.Controller.extend中,我的各種操作方法放置在這裏似乎沒有辦法。整個模型消失(無數據),添加數據也不起作用。沒有任何反應,沒有錯誤,沒有任何反應這些方法可能根本就沒有被調用。
任何意見「轉換」到2.3將不勝感激。
現在我有
export default Ember.Controller.extend({
proxy: {},
actions: {
setUnknownProperty: function(key, value) {
console.log("Set the unknown property: " + key + " to: " + value);
this.proxy[key] = value;
console.log("Proxy: ");
console.log(this.proxy);
},
testAction: function() {
console.log("fired");
}, flush: function() {
console.log("Flush called");
for(var key in this.proxy) {
console.log("Flushing " + key);
this.set('model.'+key, this.proxy[key]);
console.log("Saving");
this.get('model.'+key).save();
}
}
}