-
15 Feb 2012 6:30 AM #1
4.1 Beta 2 - Json reader and createAccessor
4.1 Beta 2 - Json reader and createAccessor
Hi,
I'm trying to test my application in the Beta 2 and I have a question regarding the internals of the Json reader.
Previously, I overrided the method "createAccessor" for custom needs. Now the method is still there but there is the new one "createFieldAccessExpression" which has the same documentation but seems to be called elsewhere.
What is exactly the purpose of this new function and why not merge the two ?
-
15 Feb 2012 6:40 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
It looks like createFieldAccessExpression is for mapping of fields to response fields.
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.
-
15 Feb 2012 7:44 AM #3
Ok I see ... now a function is builded as a string to extract data. Want I want is a "NullSafe" json extractor.
For example, if mapping is user.description, I want to handle the fact that "user" can be null...
I don't know how to achieve this in the new format ... my old custom function was doing something like this :
Code:var parts = expr.split('.'); return function(value) { for (var i =0; i < parts.length; i++) { if (!value) return null; value = value[parts[i]]; } return value; };
-
23 Feb 2012 1:29 AM #4
Don Griffin
Ext JS Development Team Lead
Check the docs. Learn how to (properly) report a framework issue and a Sencha Cmd issue
"Use the source, Luke!"
-
23 Feb 2012 1:33 AM #5
A converter, if it can achieve your goals, is much better than operating on the private methods behind the reader. Obviously, one has to do what one has to do...
Don Griffin
Ext JS Development Team Lead
Check the docs. Learn how to (properly) report a framework issue and a Sencha Cmd issue
"Use the source, Luke!"
-
2 May 2012 8:04 AM #6
I've just had the same kind problem during my migration from 4.0.7 to 4.1.0
Here is the convert function that I wrote to address this behaviour :
In 4.0.7 my model was :Code:var jsonNullSafe = function(field, prop) { return function(v, record) { var json = record.get(field) || {}, value = json[prop]; return value || v; } }; Ext.define('Book', { extend: 'Ext.data.Model', fields: [{ name: 'title' }, { name: 'author' }, { name: 'authorFirstName', convert: jsonNullSafe('author', 'fn') }, { name: 'authorLastName', convert: jsonNullSafe('author', 'ln') }] });
Code:Ext.define('Book', { extend: 'Ext.data.Model', fields: [{ name: 'title' }, { name: 'authorFirstName', mapping: 'author.fn' }, { name: 'authorLastName', mapping: 'author.ln' }] });


Reply With Quote