-
15 Feb 2012 8:21 AM #1
Answered: Exception when trying to read an empty store
Answered: Exception when trying to read an empty store
Hi guys I have an application that stores locations to a store. When it starts up I want to check if the user has any locations stored, I'm doing this as follows:
Basically I'm trying to load the first item and if it is successful do one thing, otherwise do something else. When there is data in the store this works fine, but when the store is empty I get an Exception:Code:launch: function() { //create store ref var store = Ext.create('Ext.data.Store', { model: 'MyApp.model.Location' }); //do we have at least one item in the store? MyApp.model.Location.load(1, { success: function(location) { console.log("Got an item"); }, failure: function(record) { console.log("Failed to retrieve item"); } }); }
Uncaught TypeError: Cannot read property 'id' of null
any tips on a better way of doing this?
Thanks!
-
Best Answer Posted by mitchellsimoens
You should be looking at the store to see if there is the record in it, not load a model instance.
-
15 Feb 2012 8:55 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 436
- Answers
- 3107
You should be looking at the store to see if there is the record in it, not load a model instance.
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.
-
16 Feb 2012 5:46 AM #3


Reply With Quote