Overwite JsonReader.readRecords()

// Json Plugin    //struts2    // Ext JsonReader



root:[

{'id':"",'name':""},

{'id':""}

]



ColumnModel : Fiedls  为  {name:'id'}{name:'name'}


读第二行时  取root[2].name就会出错


----------------------------

重写 JsonReader  readRecords方法

Ext.override(Ext.data.JsonReader,{
readRecords : function(o){
         ...
         var records = [];
        for(var i = 0; i < c; i++){
            var n = root[i];
            var values = {};
            var id = this.getId(n);
            for(var j = 0; j < fl; j++){
            f = fi[j];

    try{

        var v = this.ef[j](n);
        values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue, n);

    }catch(e){
        values[f.name] =    ?.   f.defaultValue

    }

    ...

});
 

加try ...   因JSON数据不规则  读取异常时  设为默认值

你可能感兴趣的:(c,json,ext,F#,J#)