在 Ember Data 中,在我声明一个模型并提交到商店后,我检索它并尝试为特定字段设置一个新值,但是它给了我这个错误:
Uncaught Error: <DS.StateManager:ember227> could not respond to event setProperty in state rootState.loaded.created.inFlight.
Ember.StateManager.Ember.State.extend.sendRecursively ember-latest.min.js:17
Ember.StateManager.Ember.State.extend.sendRecursively ember-latest.min.js:17
Ember.StateManager.Ember.State.extend.sendRecursively ember-latest.min.js:17
Ember.StateManager.Ember.State.extend.sendRecursively ember-latest.min.js:17
Ember.StateManager.Ember.State.extend.sendRecursively ember-latest.min.js:17
Ember.StateManager.Ember.State.extend.send ember-latest.min.js:17
DS.Model.Ember.Object.extend.send ember-data.js:2540
DS.Model.Ember.Object.extend.setProperty ember-data.js:2549
(anonymous function) ember-data.js:2682
n.set ember-latest.min.js:14
c ember-latest.min.js:14
Ember.Observable.Ember.Mixin.create.set ember-latest.min.js:15
(anonymous function)
详细信息(主要是样板代码):
/* create store */
App.store = DS.Store.create({
revision: 2,
// adapter: DS.LocalStorageAdaptor.create({}),
adapter: DS.DjangoTastypieAdapter.create({
serverDomain: "http://localhost:8000",
tastypieApiUrl: 'api/v1/',
});
});
// declare model
App.StyleData = DS.Model.extend({
...
storageID: DS.attr('number', {defaultValue: 0, key: 'storageID'}),
didCreate: function(){
// console.log('didcreate');
},
});
/*create new model */
App.store.createRecord(App.StyleData, {storageID: 0});
App.store.commit();
/* retrieve model and set new value for storageID */
var mod = App.store.findAll( App.StyleData );
var mod1 = mod.get('modelCache')[0];
mod1.set('storageID', 10) // here the error above is thrown