-
2 Dec 2011 7:28 AM #1
Answered: Issues Grabbing JSON - I'm so close.
Answered: Issues Grabbing JSON - I'm so close.
Hi all,
Sooooo close to nailing this but I can't get it to work. Problem is that it's not loading the JSON and displaying it. My JSON file is valid (I checked it at JSON Lint) and is very simple. Here's the JSON which is in the same directory as app.js:
And my Sencha Touch code:Code:{ "firstName": "John", "lastName" : "Smith" }
You'll note the commented out data which is what I was using to make sure that the store was communicating with the model - which it was - it showed up just fine. I tried to take it to the next level by snagging this JSON file but it ain't working.Code:var App = new Ext.Application({ name: 'ExpEng', useLoadMask: true, launch: function () { Ext.regModel('Work', { fields: [ { name: 'firstName', type: 'string' }, { name: 'lastName', type: 'string' } ] }); Ext.regStore('workStore', { model: 'Work', proxy: { type: 'ajax', url: 'sample.json', reader: { type: 'json' } } //data: [ // { id: 1, date: new Date(), title: 'Test Note', narrative: 'This is simply a test note' } //] }); ExpEng.views.workList = new Ext.List({ id: 'workList', store: 'workStore', onItemDisclosure: function (record) { //TK }, itemTpl: '<div class="list-item-title">{firstName}</div>' }); ExpEng.views.workListContainer = new Ext.Panel({ id: 'workListContainer', layout: 'fit', html: 'This is the work list container', items: [ExpEng.views.workList] }); ExpEng.views.viewport = new Ext.Panel({ fullscreen: true, layout: 'card', cardAnimation: 'slide', items: [ExpEng.views.workListContainer] }); } });
Thanks for the help!
-
Best Answer Posted by porpoise
I replaced my JSON code with this:
But the app just hangs on the loading icon...Code:[ { "firstName": "John", "lastName" : "Smith" } ]
-
2 Dec 2011 11:08 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Your JSON is valid but it's not. The Store is expecting an Array:
Code:[ { "firstName": "John", "lastName": "Smith" } ]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.
-
2 Dec 2011 12:34 PM #3
Made the change
Made the change
I replaced my JSON code with this:
But the app just hangs on the loading icon...Code:[ { "firstName": "John", "lastName" : "Smith" } ]
-
2 Dec 2011 12:41 PM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Odd... worked 100% for me.
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.
-
2 Dec 2011 12:58 PM #5
Error I get
Error I get
I get this error in console:
TypeError: 'undefined' is not an object (evaluating 'a.length')
It says it's in sencha-touch.js:6
Does that yield any clues?
-
2 Dec 2011 1:00 PM #6
Updated error
Updated error
Oops. That wasn't very helpful, was it. From the debug.js I get this error from console:
TypeError: 'undefined' is not an object (evaluating 'records.length')
from
sencha-touch-debug:7231
-
2 Dec 2011 1:07 PM #7
Solved it!
Solved it!
Ha - solved it. I wasn't running my app from a web server. I did that and now it works! Thanks for your help!!


Reply With Quote