-
Can't save into store
After solving a few problems, at last I can see my view but I came across another problem: I can't save my data (model) into a store. Here is my code:
Code:
var currentUser= this.profileView.getRecord();
this.profileView.updateRecord(currentUser);
var errors = currentUser.validate();
if (!errors.isValid()) {
currentUser.reject();
Ext.Msg.alert('Wait!', errors.getByField('name')[0].message, Ext.emptyFn);
return;
}
// save user profile to data store
var store = this.getStore('App.store.MyProfile');
if (null == store.findRecord('id', currentUser.data.id)) {
store.add(currentUser);
} else {
currentUser.setDirty();
}
Almost the same code running in Sencha Touch 1.1 has no problem. But failed at Sencha Touch 2. The error message is:
Uncaught TypeError: Cannot call method 'create' of undefined
It's either in this.profileView.updateRecord(currentUser); or store.add(currentUser);. I checked the store and currentUser, they seems to be correct. What could be wrong? (My store's autoSync is set to true, so I think I don't need to call store.sync() after the store.add())
Thanks
-
If the store.add is failing then autoSync wouldn't work so there would be no request. It's kind of hard to debug something for someone when they don't step through to figure out what line is failing.
-
1 Attachment(s)
Here is the call stacks:
Attachment 30428
Does it help? I totally got no clue.
Thanks
-
store.add looks like it's ok, it's the syncing that isn't working.
-
Yes. I believe so. When I turn off autoSync, the code will not fail until I add store.sync at the end. So the problem must be related to sync. I'll debug more. Thanks
-
I change the autoSync to false and manually run store.sync(). Yes, it failed in store.sync().
Here is the code inside sync() function in sencha-touch-all.js:
Code:
sync: function() {
if (typeof this.proxy.sync != 'function') {
this.callParent(arguments);
}else{
this.proxy.sync(this);
}
},
if (typeofthis.proxy.sync != 'function') return true, so this.proxy.sync(this); is never been called. I don't know whether that's the problem.
Here is my source code for the store:
Code:
Ext.define('App.store.MyProfile', {
extend : 'Ext.data.Store',
model : 'App.model.User',
autoLoad : true,
//autoSync : true,
proxy: {
type: 'localstorage',
id: 'my-profile-store'
}
});
Somebody mentioned the localstorage in Sencha Touch 2.0 is broken. Is this true? If this is the cause, can I use JSON and save my data back to JSON file in server?
Thanks
-