1. #1
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    9
    Answers
    1
    Vote Rating
    0
    padr3 is on a distinguished road

      0  

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

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    9
    Answers
    1
    Vote Rating
    0
    padr3 is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Have you tried a testing build?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    9
    Answers
    1
    Vote Rating
    0
    padr3 is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread