1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    17
    Vote Rating
    0
    ozkmat is on a distinguished road

      0  

    Default Unanswered: JSON Store doesn't load Data from JSON-File

    Unanswered: JSON Store doesn't load Data from JSON-File


    Hi there,

    I have been thru this complete Forum, but I can't find my mistake. I don't get any Errors or Warnings for the JSON File. I had some but managed to get rid of them, that's why I'm sure, that the File should be loaded. But the Store is empty on the Output in my View (getCount() == 0).

    My Store:
    Code:
    Ext.define("Jadeva.store.LocalStore", {
        extend: 'Ext.data.Store',
        id: 'jadevalocalstore',
        config: {
            autoLoad: true,  
            model : "Jadeva.model.JadevaModel",
            proxy: {
                type: 'ajax',
                url : 'data.json',
                reader: {
                      type : 'json'
                     }
             },
             sorters : [{
                 property : "City",
                 direction : "ASC"
             }]
        }
      });
    My Model:
    Code:
    Ext.define("Jadeva.model.JadevaModel", {
        extend : "Ext.data.Model",
        config : {
            fields : [{name : 'City',type : 'string'},
                      {name : 'State',type : 'string'}]
        }
    });
    My Controller (part of it)
    Code:
    ...
    launch : function() {
                    this.callParent(arguments);
                    Ext.getStore("LocalStore").load();
                    console.log("launch");
                },
                init : function() {
                    this.callParent(arguments);
                    console.log("init");
                }
    ...
    My View:
    Code:
    var store = Ext.getStore("LocalStore");
    console.info("----------------- store.getCount(): " + store.getCount());
    And my JSON File:
    Code:
    [{
    "City": "Aach",
    "State": "Trier-Saarburg",
    },{
    "City": "Aach, Stadt",
    "State": "Konstanz"
    }]
    Also im sure the File is on the right location, it's on the same Level as the index.html. So I have no Idea why the Store is empty. I compared my Codes with other that should work, but I couldn't find my mistake.

    Thanks in advance, Tina

    I use: Phonegap 2.1.0, Sencha Touch 2.0.1.1 Commercial and I test it on Anroid 4.0.4.

  2. #2
    Sencha User
    Join Date
    Aug 2012
    Posts
    56
    Answers
    7
    Vote Rating
    11
    bumpy will become famous soon enough

      0  

    Default


    Maybe you're trying to display the store count before it was fully loaded.
    Try using this code in your view:
    Code:
    var store = Ext.getStore("LocalStore");
    store.load(function(records, operation, success) {
    	if (success)
    		console.log(store.getCount());
    });
    If it works you can remove the load call in the launch method.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    17
    Vote Rating
    0
    ozkmat is on a distinguished road

      0  

    Default


    Hi, thanks for the fast reply.

    I tried what you suggested, but 'success' is never true.
    I also made an Output before the if, that is executed once and 'success' is not true then.

    Edit: also 'records' is empty... it's not 'null' or [object Object], it just displays nothing. 'operation' is displayed as [object Object]

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,329
    Answers
    3540
    Vote Rating
    847
    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


    That store works for me loading that json (you have a trailing comma in your json also):

    Code:
    new Jadeva.store.LocalStore({
        listeners : {
            load : function(store, recs) {
                console.log(recs.length, store.getCount()); //both are 2
            }
        }
    });
    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.

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    17
    Vote Rating
    0
    ozkmat is on a distinguished road

      0  

    Default


    When I use your Code, I get following Error before the Output (that in my case are still both '0')
    Unknown chromium error: -6
    I googled a bit and it says, that this error occures when the File is not found. But I don't see how I had put it wrong. It's the same Level as the index.html and even when I put it in the Level of the View, the Error stays the same, don't know what else would make sense.

    I was so sure, it reads the File, cause of the occurred Errors when it had wrong letters in it.

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,329
    Answers
    3540
    Vote Rating
    847
    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


    In my code I changed the url to match my test setup
    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.

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    17
    Vote Rating
    0
    ozkmat is on a distinguished road

      0  

    Default


    May i ask what you put in and where u put it in your Project?

    But should it be correct to put it as I did? Not sure how to specify it more clearly in an App.

  8. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,329
    Answers
    3540
    Vote Rating
    847
    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


    All it is the relative location of the json file
    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: 2

Tags for this Thread