-
11 Oct 2011 8:26 AM #1
Cannot read property 'xxx' of null
Cannot read property 'xxx' of null
The JSON I am getting from my http request usually returns like so:
Unfortunately, if the parent_series fields is left blank it comes up null and gives the error "Cannot read property 'parent_series' of null".Code:- { id: 1209902856001 name: "test video" - customFields: { parent_series: "tv_series" } }
-
Is there anyway to just map an empty string if customFields is null? My code is below. Thanks!!Code:- { id: 1209882934001 name: "test video 2" customFields: null }
Code:brightcove.models.BrightcoveVideos = Ext.regModel("brightcove.models.BrightcoveVideos", { fields: [ {name: "video_name", type: "string", mapping: "name"}, {name: "parent_series", type: "string", mapping: "customFields.parent_series"} ] });
-
11 Oct 2011 1:25 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Specify a convert function on the field that returns an empty string if it is null
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.
-
11 Oct 2011 1:34 PM #3
-
11 Oct 2011 2:02 PM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Something like this...
Code:{ name : 'firstName', mapping : 'first name', type : 'string', convert : function(val) { if (!val) { val = ''; } return val; } }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.
-
11 Oct 2011 4:34 PM #5
-
11 Oct 2011 6:21 PM #6
rgilkes can you show me your store code as am also trying to read Json data but fails.
Code:Store = new Ext.data.Store({ model: 'User', autoLoad:false, proxy: { type: 'ajax', url : 'webservice', reader: { type: 'json' } } });
-
12 Oct 2011 7:45 AM #7
My store code is below...hope it helps!
Code:brightcove.stores.playlists = new Ext.data.Store({ storeId: 'store_playlists', model: 'brightcove.models.BrightcovePlaylists', autoLoad: true, sorters: [{ property: 'playlist_name', direction: 'ASC' }], proxy: { type: 'scripttag', url: 'http://api.brightcove.com/services/library?command=find_all_playlists', reader: { type: 'json', root: 'items' }, extraParams: { get_item_count: 'true', playlist_fields: 'name,id,filterTags', token: 'API TOKEN GOES HERE' } } })


Reply With Quote