extjs store 复杂json_extjs 2.3 修复 jsonstore 嵌套多级引用数据NULL的BUG

Ext版本:2.3.0

搜索到一篇有用的链接是:

我在使用Ext.grid.GridPanel时,用到了多级JSON。

如:

{

"data": [

{

"id" : 1,"amount" : 100,"costumer" : {

"id" : 123,"name" : "Luis Valdés"

}

},{

"id" : 2,"amount" : 100

}

]

}

在定义列时有 {header:'id',dataIndex:'id'},

{header:'amount',dataIndex:'amount'},

{header:'cutomerid','dataIndex:'customer.id'},

{header:'customerName',dataIndex:'customer.name'}

当customer不为空时都正常,空的时候就显示不出来。解决办法如下,将Ext.data.JsonReader的getJsonAccessor现有方法:

getJsonAccessor: function(){

var re = /[\[\.]/;

return function(expr) {

try {

return(re.test(expr))

? new Function("obj","return obj." + expr)

: function(obj){

return obj[expr];

};

} catch(e){}

return Ext.emptyFn;

};

}(),

替换为:

getJsonAccessor: function(){

var re = /[\[\.]/;

return function(expr) {

try {

return(re.test(expr))

? new Function("obj","try{return obj." + expr+"}catch(e){}return '';")

: function(obj){

return obj[expr];

};

} catch(e){}

return Ext.emptyFn;

};

}(), 即可解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值