Results 1 to 6 of 6

Thread: Error on build only when loading data form proxy

  1. #1
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    9
    Answers
    1
    Vote Rating
    0
      0  

    Default Answered: Error on build only when loading data form proxy

    Hello,

    I am using a JSON Proxy, which works fine in development, I can load data locally or from a production server.

    However, when I build using sencha cmd I get the following error
    "Uncaught TypeError: Cannot call method 'indexOf' of null"

    when loading the build in a browser, or running it Xcode simulator or on a device.

    If I remove the autoLoad from the store I don't get the error, but manually loading it using load() the error returns

    any ideas?

    Code:
    Ext.define('ActivityDay.store.Teams', {
        extend: 'Ext.data.Store',
        config: {
            model: 'ActivityDay.model.Team',
            proxy: {
                type: 'ajax',
                url : apiAddress,
                reader: {
                    type: 'json',
                    rootProperty: 'teams'
                },
            },
            autoLoad: true
        }
    });

  2. I'd use a utility singleton to hold that type of info:

    Code:
    Ext.define('MyApp.util.Config', {
        singleton : true,
    
        config : {
            environment : '',
            apiAddress  : ''
        },
    
        applyEnvironment : function() {
            var env = 'dev';
    
            //maybe check url or something to choose what is prod automatically
            if (false) {
                env = 'prod';
            }
    
            return env;
        },
    
        applyApiAddress : function() {
            var env       = this.getEnvironment(),
                addresses = {
                    dev  : 'http://localhost/ActivityDay',
                    prod : 'http://example.production.com'
                };
    
            return addresses[env];
        }
    });

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

    Default

    Where is the error being thrown? You need to do some debugging to be more equipped to investigate the error. What does the model look like and why isn't your store requiring it? What does the response look like (sample)?
    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 Premium Member
    Join Date
    Mar 2013
    Posts
    9
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Hey Mitchell,

    the error is being thrown from line 1 of app.js (the minified version)

    It's quite hard to debug as it works fine in development its only the build that the error occurs

    The response from the server is:

    Code:
    {"teams":[{"id":"1","title":"Blue","captains":"Tim and Nic (Geno)","colour":"0000FF","deleted":"0","addTime":null},{"id":"3","title":"Green","captains":"Dykesy","colour":"00FF00","deleted":"0","addTime":null},{"id":"2","title":"Red","captains":"Brett and _____","colour":"FF0000","deleted":"0","addTime":null},{"id":"4","title":"Yellow","captains":"Whitey","colour":"","deleted":"0","addTime":null}],"trophies":[{"id":"1","year":"2007","team_id":"1","deleted":"0","addTime":null},{"id":"2","year":"2008","team_id":"1","deleted":"0","addTime":null},{"id":"3","year":"2009","team_id":"2","deleted":"0","addTime":null},{"id":"4","year":"2010","team_id":"2","deleted":"0","addTime":null}],"secondsUntilStart":2123064}
    I have added the model to the requires of the store, still get the error.

    strange that it works fine in development, but error occurs in the build.

    is there anything I can give you to help?

    Thanks,
    Pat

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

    Default

    Have you tried a testing build?
    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

  6. #5
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    9
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Hey Mitchell,

    the testing build helped debug, the error was happening because the variable apiAddress was null.

    where should variables be assigned? I had this one at the top of app.js

    Code:
    
    var development = true;
    
    
    if(development)
        var apiAddress = 'http://localhost/ActivityDay';
    else
        var apiAddress = 'http://example.production.com';
    Thanks again

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

    Default

    I'd use a utility singleton to hold that type of info:

    Code:
    Ext.define('MyApp.util.Config', {
        singleton : true,
    
        config : {
            environment : '',
            apiAddress  : ''
        },
    
        applyEnvironment : function() {
            var env = 'dev';
    
            //maybe check url or something to choose what is prod automatically
            if (false) {
                env = 'prod';
            }
    
            return env;
        },
    
        applyApiAddress : function() {
            var env       = this.getEnvironment(),
                addresses = {
                    dev  : 'http://localhost/ActivityDay',
                    prod : 'http://example.production.com'
                };
    
            return addresses[env];
        }
    });
    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

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
  •