-
17 Oct 2012 5:05 AM #1
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:
My Model: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 Controller (part of it)Code:Ext.define("Jadeva.model.JadevaModel", { extend : "Ext.data.Model", config : { fields : [{name : 'City',type : 'string'}, {name : 'State',type : 'string'}] } });
My View:Code:... launch : function() { this.callParent(arguments); Ext.getStore("LocalStore").load(); console.log("launch"); }, init : function() { this.callParent(arguments); console.log("init"); } ...
And my JSON File:Code:var store = Ext.getStore("LocalStore"); console.info("----------------- store.getCount(): " + store.getCount());
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.Code:[{ "City": "Aach", "State": "Trier-Saarburg", },{ "City": "Aach, Stadt", "State": "Konstanz" }]
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.
-
17 Oct 2012 5:17 AM #2
Maybe you're trying to display the store count before it was fully loaded.
Try using this code in your view:
If it works you can remove the load call in the launch method.Code:var store = Ext.getStore("LocalStore"); store.load(function(records, operation, success) { if (success) console.log(store.getCount()); });
-
17 Oct 2012 7:11 AM #3
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]
-
19 Oct 2012 4:31 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
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
________________
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.
-
19 Oct 2012 5:40 AM #5
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.
-
19 Oct 2012 5:41 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
In my code I changed the url to match my test setup
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.
-
19 Oct 2012 5:50 AM #7
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.
-
19 Oct 2012 5:52 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
All it is the relative location of the json file
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.


Reply With Quote