-
12 Feb 2012 8:25 PM #1
Answered: STB2, JSON data in DataStore.Raw but not in DataStore.Data
Answered: STB2, JSON data in DataStore.Raw but not in DataStore.Data
I tried to update to B2, but my jsonp stores stopped loading the fetched data into the associated models. It worked in B1 and below, but not in B2.
my model
my local proxyCode:Ext.define('MyApp.model.Post', { extend: 'Ext.data.Model', config: { idProperty: 'localId', fields: [ {name: "localId", type: "auto"}, {name: "id", type: "int"}, ... {name: "text", type: "string"}, ... ], proxy: 'posts', }, });
my remote storeCode:Ext.define('MyApp.proxy.Posts', { extend : 'Ext.data.proxy.LocalStorage', alias: 'proxy.posts', config: { id: 'localposts', model: 'MyApp.model.Post', } }) ;
when my view initializesCode:Ext.define('MyApp.store.RemotePosts', { extend : 'Ext.data.Store', config: { id: 'RemotePosts', model: 'MyApp.model.Post', remoteFilter: true, proxy: { type: 'jsonp', url: 'http://mydomain.com/post/fetch', reader: { type: 'json', root: 'results' }, }, }, });
Here is what the records variable looks like in chrome. As you can see the data is in the raw results but not in the data itself.Code:var remotePosts = Ext.create('MyApp.store.RemotePosts', { remoteFilter: true, filters: filters, }); remotePosts.load({ callback: function(records, operation, success) { for (i in records) { var currentRecord = records[i]; ... } } });
Any ideas?Code:- 0: Ext.apply.create.Class
- _data: Object
- data: Object
- id: null
- localId: "ext-record-12"
- ...
- text: null
- __proto__: Object
- id: "ext-record-12"
- internalId: "ext-record-12"
- modified: Object
- phantom: true
- raw: Object
- next_page: "?page=2&max_id=164575332152774658&q=my+search"
- page: 1
- refresh_url: "?page=2&max_id=164575332152774658&q=my+search"
- results: Array[17]
- 0: Object
- id: "144221157757947904"
- id_str: "144221157757947904"
- text: "Some Text"
- ...
- __proto__: Object
- 1: Object
- ...
- 0: Object
This has been reported in Ext JS 4 as well, but there's been no answer and since it only happens in B2, I figured I could get a better answer here.
http://www.sencha.com/forum/showthre...DataStore.Data
- 0: Ext.apply.create.Class
-
Best Answer Posted by curmil
I figured it out, the root property in the reader needed to be changed to rootProperty, so this:
becameCode:Ext.define('MyApp.store.RemotePosts', { extend : 'Ext.data.Store', config: { id: 'RemotePosts', model: 'MyApp.model.Post', remoteFilter: true, proxy: { type: 'jsonp', url: 'http://mydomain.com/post/fetch', reader: { type: 'json', root: 'results' }, }, }, });
Code:Ext.define('MyApp.store.RemotePosts', { extend : 'Ext.data.Store', config: { id: 'RemotePosts', model: 'MyApp.model.Post', remoteFilter: true, proxy: { type: 'jsonp', url: 'http://mydomain.com/post/fetch', reader: { type: 'json', rootProperty: 'results' }, }, }, });
-
13 Feb 2012 5:38 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
- Answers
- 3102
How many records are returned in your load callback?
Also, the data property shouldn't be used, the _data property is the one to use.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.
-
13 Feb 2012 9:02 PM #3
The store returns a record set with a single record in it. That record has no data in the data or _data properties except for the id attribute (localId). The actual 17 records that should have been in the recordset exist in the raw property of the single record.
-
13 Feb 2012 9:30 PM #4
I figured it out, the root property in the reader needed to be changed to rootProperty, so this:
becameCode:Ext.define('MyApp.store.RemotePosts', { extend : 'Ext.data.Store', config: { id: 'RemotePosts', model: 'MyApp.model.Post', remoteFilter: true, proxy: { type: 'jsonp', url: 'http://mydomain.com/post/fetch', reader: { type: 'json', root: 'results' }, }, }, });
Code:Ext.define('MyApp.store.RemotePosts', { extend : 'Ext.data.Store', config: { id: 'RemotePosts', model: 'MyApp.model.Post', remoteFilter: true, proxy: { type: 'jsonp', url: 'http://mydomain.com/post/fetch', reader: { type: 'json', rootProperty: 'results' }, }, }, });
-
22 Feb 2012 6:19 PM #5
Thank you! You saved me from two more hours of scratching my head.


Reply With Quote