Results 1 to 7 of 7

Thread: Cannot read property 'xxx' of null

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
      0  

    Default 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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,029
    Vote Rating
    1368
      0  

    Default

    Specify a convert function on the field that returns an empty string if it is null
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
      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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,029
    Vote Rating
    1368
      0  

    Default

    Something like this...

    Code:
    {
        name : 'firstName',
        mapping : 'first name',
        type : 'string',
        convert : function(val) {
            if (!val) { val = ''; }
            return val;
        }
    }
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Oct 2011
    Posts
    4
    Vote Rating
    0
      0  

    Default

    Using that method worked! Thanks!!

  6. #6
    Touch Premium Member
    Join Date
    Jan 2009
    Posts
    61
    Vote Rating
    1
      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
      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'
            }
        }
    })

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •