1. #1
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default Small problem in ArrayReader.js

    Small problem in ArrayReader.js


    There's a problem when the id field is a numeric index into the data array, and the id is in index zero.

    this statement:

    Code:
    	        var id = (sid && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
    yields null when (sid == 0). The first truth test on it fails.

    The following code works:

    Code:
    Ext.extend(Ext.data.ArrayReader, Ext.data.JsonReader, {
        readRecords : function(o){
            var sid = this.meta ? this.meta.id : undefined; // <-- changed
        	var recordType = this.recordType, fields = recordType.prototype.fields;
        	var records = [];
        	var root = o;
    	    for(var i = 0; i < root.length; i++){
    		    var n = root[i];
    	        var values = {};
    	        var id = ((sid != undefined) && (n[sid] !== "") ? n[sid] : null); // <-- changed
    	        for(var j = 0, jlen = fields.length; j < jlen; j++){
                    var f = fields.items[j];
                    var k = f.mapping || j;
                    var v = n[k] !== undefined ? n[k] : f.defaultValue;
                    v = f.convert(v);
                    values[f.name] = v;
                }
    	        var record = new recordType(values, id);
    	        record.json = n;
    	        records[records.length] = record;
    	    }
    	    return {
    	        records : records,
    	        totalRecords : records.length
    	    };
        }
    });

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    I am worried about it = undefined (if the id is not present). What about this paranoid check?

    var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Whatever works!

Similar Threads

  1. My tabs are so small!
    By irishdunn in forum Ext 1.x: Help & Discussion
    Replies: 10
    Last Post: 12 Dec 2007, 1:23 PM
  2. Small fix for PagingToolbar
    By gordon in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 26 Feb 2007, 5:11 AM
  3. small bug in forums
    By reignman in forum Ext 1.x: Bugs
    Replies: 2
    Last Post: 25 Jan 2007, 12:41 PM
  4. Small Problem with layout
    By joerg.battermann in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 15 Jan 2007, 11:21 PM
  5. Small fix for TabPanel
    By gordon in forum Ext 1.x: Bugs
    Replies: 1
    Last Post: 27 Sep 2006, 4:18 AM

Thread Participants: 1