-
6 Dec 2012 2:22 PM #1
Store same Model via a different response format
Store same Model via a different response format
What's the best way to get server data into a store if the response format is different from one web service to another? Example:
user/1 returns
...but favorites/2 returnsCode:{response: {id:1, name:'Charles'} }
...and my Person model has a convert function likeCode:{data:{ person:{id:2, name:'Snoopy'}, favorites:[ {id:1, name:'Charles'}, {id:3, name:'Woodstock'} ] }}
In other words, how can I ensure that Charles gets stored properly regardless of the source web service?Code:Ext.define('Person',{ extend:'Ext.data.Model', config:{ fields:[ { name:'name', type:'string', convert:function(value,record){ //If the name is Charles, change it to Blockhead if(value == 'Charles'){return 'Blockhead';} else{return value;} } } ] } })
-
8 Dec 2012 6:11 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Looks like you have different roots, you need to have the reader configured to use the root that you need.
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.
-
10 Dec 2012 8:21 AM #3
@Mitchell, I need a way to accommodate both services with the same Model and Store. Are you suggesting that I do something like this (shown below)?
Code:var store = Ext.getStore('Person'), proxy = store.getProxy(); proxy.setUrl('favorites/2'); proxy.getReader().setRootProperty('data.favorites'); store.load();


Reply With Quote