-
17 Jan 2012 3:23 AM #1
Unanswered: JSON STORE PROBLEM: Sencha doesn't call json decode on my data
Unanswered: JSON STORE PROBLEM: Sencha doesn't call json decode on my data
Good day folks,
I've a problem with JSONSTORE.. I'll write my code, and then I'll tell you where the problem is:
My response is well formatted, so after that some sencha functions are called I get:Code:Ext.define('newModel', { extend: 'Ext.data.Model', fields: [{ name: 'idn', type: 'int' }, { name: 'text', type: 'string' }, { name: 'dsc', type: 'string' }] }); var tabpanel = Ext.create('Ext.tab.Panel', { tabBar: { docked: 'bottom', layout: { pack: 'center' } }, fullscreen: true, defaults: { scrollable: true }, items: [{ xtype: 'list', title: 'Zoom', iconCls: 'bookmarks', itemTpl: '{title}', itemTpl: '<div>{idn} - {text} - {dsc}</div>', store: { model: 'newModel', proxy: { type: 'ajax', api: { create: undefined, read: this.AJAX_REQUEST_URL update: undefined, destroy: undefined }, reader: { type: 'json', root: 'mResponseData.rows.results', successProperty: 'bRequestResult', totalProperty: 'mResponseData.totalCount' } }, autoLoad: true } }] });
successProperty => myResponse.bRequestResult ( PERFECT! )
totalProperty =>myResponse.mResponseData.totalCount ( PERFECT! )
root =>myResponse.mResponseData.rows.results ( PROBLEM! )
The problem is that root value is a JSON string
and Sencha doesn't call a json decode on it...Code:"[{"idn":1,"text":"text1","dsc":"aaa"},{"idn":2,"text":"text2","dsc":"bbb"}{"idn":3,"text":"text3","dsc":"ccc"}]"
so ... sencha use the string as array, and I get a store with 116 records ( one for each char ) without info, because sencha doesn't discovery fields like idn, mane and dsc...
If I change the code and add the command:
root = Ext.JSON.decode( root )
all works fine....
can help me to find the problem.
Thanks so much!
-
17 Jan 2012 6:52 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
- Answers
- 3106
All JsonStore does is setup a proxy and a json reader. The only time json reader will read JSON is if you are remotely loading data. If you are using add or insert or loadRecords, you have to pass in JavaScript or Ext.data.Model instances.
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.
-
17 Jan 2012 7:27 AM #3
I don't understand x (
I don't understand x (
Hi Mitchell,
and thanks for your aids...
I've read your message, but I doesn't understand it very well : (
I load remote data ( from this.AJAX_REQUEST_URL ) ...
and Sencha uses very well the reader information ( root, successproperty, ecc ecc )
but it doesn't call json decode ( because I missing something )
so.. server give me that data:
Sencha decode in this:{"bRequestResult":true,"mResponseData":{"rows":{"results":"[{\"idn\":1,\"text\":\"text1\",\"dsc\":\"aaa\"},{"results":"[{\"idn\":2,\"text\":\"text2\",\"dsc\":\"bbb\"},.]"},"totalCount":3}}
and that is good... if only results wasCode:bRequestResult: true mResponseData: Object rows: Object results:"[{"idn":1,"text":"text1","dsc":"aaa"},{"idn":2,"text":"text2","dsc":"bbb"}, ecc ecc]" totalCount: 3
Ext.JSON.decode( "[{"idn":1,"text":"text1","dsc":"aaa"},{"idn":2,"text":"text2","dsc":"bbb"}
{"idn":3,"text":"text3","dsc":"ccc"}]")
the world will be more beautiful : )
Maybe the answear is in your previous post.. can repeat it in simplest mode? : )
Thanks again!!
-
17 Jan 2012 7:30 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
- Answers
- 3106
You need to set a root and successProperty on the reader to map to the correct level in your JSON
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.
-
17 Jan 2012 8:27 AM #5
But I've done it...You need to set a root and successProperty on the reader to map to the correct level in your JSON
and it works ( without reader sencha doesn't read data in mResponseData.rows.results )
but result value is get as string and not decoded in array ...
I dont't know because it happenes ( is my first time with sencha touch) but is like if the params
type: 'json' was not used... o_O
Code:store: { model: 'newModel', proxy: { type: 'ajax', api: { create: undefined, read: this.AJAX_REQUEST_URL update: undefined, destroy: undefined }, reader: { type: 'json', root: 'mResponseData.rows.results', successProperty: 'bRequestResult', totalProperty: 'mResponseData.totalCount' } }, autoLoad: true }
-
17 Jan 2012 12:07 PM #6
The data package has had a major refactor since PR3, and it will be available in the next release. I'd wait for that release and see if it works then. If not, submit a bug report.
Sencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.
-
18 Jan 2012 5:42 AM #7


Reply With Quote