Results 1 to 3 of 3

Thread: Exception when trying to read an empty store

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    10
    Vote Rating
    1
      0  

    Default 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:

    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");
                }
            });
        }
    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:

    Uncaught TypeError: Cannot read property 'id' of null

    any tips on a better way of doing this?

    Thanks!

  2. You should be looking at the store to see if there is the record in it, not load a model instance.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    You should be looking at the store to see if there is the record in it, not load a model instance.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    10
    Vote Rating
    1
      0  

    Default

    Perfect - many thanks mitchellsimoens.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •