extjs 2.3 修复 jsonstore 嵌套多级引用数据NULL的BUG
发布时间:2020-12-16 19:28:04 所属栏目:百科 来源:网络整理
导读:Ext版本:2.3.0 搜索到一篇有用的链接是: JsonStore and nested/multi level data in a GridPanel 我在使用Ext.grid.GridPanel时,用到了多级JSON。 如: {"data": [{ "id" : 1,"amount" : 100,"costumer" : { "id" : 123,"name" : "Luis Valdés" }},{ "id
|
Ext版本:2.3.0 搜索到一篇有用的链接是: JsonStore and nested/multi level data in a GridPanel
如: {
"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;
};
}(), 即可解决。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
