1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
    rgilkes is on a distinguished road

      0  

    Default 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:
    Code:
    - {
    id: 1209902856001
    name: "test video"
     - customFields: {
         parent_series: "tv_series"
     }
    }
    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: 1209882934001
    name: "test video 2"
    customFields: null
    }
    Is there anyway to just map an empty string if customFields is null? My code is below. Thanks!!

    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"}
        ]
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,117
    Vote Rating
    855
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Specify a convert function on the field that returns an empty string if it is null
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
    rgilkes is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Specify a convert function on the field that returns an empty string if it is null
    Pardon my ignorance (kinda new to this all), but where would the function I make to convert it go? Would it go in the mapping parameter? i.e. {name: "parent_series", type: "string", mapping: checkSeries("customFields.parent_series")}

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,117
    Vote Rating
    855
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
    rgilkes is on a distinguished road

      0  

    Default


    Using that method worked! Thanks!!

  6. #6
    Touch Premium Member
    Join Date
    Jan 2009
    Posts
    60
    Vote Rating
    1
    Designworxz is on a distinguished road

      0  

    Default


    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'				            }        }    });

  7. #7
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
    rgilkes is on a distinguished road

      0  

    Default


    Quote Originally Posted by Designworxz View Post
    rgilkes can you show me your store code as am also trying to read Json data but fails.
    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'
            }
        }
    })