-
3 Jan 2012 5:16 AM #1
Can't save into store
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:
Almost the same code running in Sencha Touch 1.1 has no problem. But failed at Sencha Touch 2. The error message is: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(); }
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
-
3 Jan 2012 5:29 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
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.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Jan 2012 6:05 AM #3
-
3 Jan 2012 6:09 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
store.add looks like it's ok, it's the syncing that isn't working.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Jan 2012 7:05 AM #5
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
-
4 Jan 2012 7:19 AM #6
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:
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?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' } });
Thanks
-
4 Jan 2012 4:01 PM #7


Reply With Quote