我正在为 Ember 数据滚动我自己的适配器。长话短说,当我调用 App.store.updateRecord(App.Model, id ) 时,我收到此错误:
Uncaught TypeError: Object <DS.Store:ember195> has no method 'updateRecord'
即使实现了 updateRecord 功能。
下面的示例代码(为了清楚起见,我将所有函数都记录到控制台而不是做他们应该做的事情)
// declare application namespace
App = Ember.Application.create();
// instantiate store
App.store = DS.Store.create({
revision: 2,
adapter: DS.LocalStorageAdapter.create(),
});
// implement adapter
DS.LocalStorageAdapter = DS.Adapter.extend({
createRecord: function(store, type, model) {
console.log('createRecord: ', type, model);
},
updateRecord: function(store, type, model) {
console.log('updateRecord: ', type, model);
},
find: function(store, type, id) {
console.log('find: ', type, id);
},
localStorage: {
set: function( ModelTyp, value ){},
get: function( ModelType ){},
}
});
// create model
App.StyleData = DS.Model.extend({
css_name: DS.attr('string', {key: 'css_name'}),
storageID: DS.attr('number', {defaultValue: 0, key: 'storageID'}),
});
// ==========================================================================
// Test Application
// ==========================================================================
App.store.createRecord(App.StyleData, { css_name: 'name' });
App.store.commit()
//console: createRecord: App.StyleData, model
App.store.find(App.StyleData, 0)
//console: find: App.StyleData, 0
App.store.updateRecord(App.StyleData, { css_name: 'new name' });
//console: Uncaught TypeError: Object <DS.Store:ember195> has no method 'updateRecord'
因为我无法弄清楚引擎盖下发生了什么,所以我几乎无所适从。