JQuery EasyUI Treegrid无法使用formatter正确显示json对象数据

时间:2013-04-05 10:41:29

标签: jquery treegrid jquery-easyui

我的jsondata内容如下:

"rows":[                                                          
        {"code":"001","name":"Name 1","addr":"Address 11","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"002","name":"Name 2","addr":"Address 13","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"003","name":"Name 3","addr":"Address 87","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"004","name":"Name 4","addr":"Address 63","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"005","name":"Name 5","addr":"Address 45","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"006","name":"Name 6","addr":"Address 16","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"007","name":"Name 7","addr":"Address 27","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"008","name":"Name 8","addr":"Address 81","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"009","name":"Name 9","addr":"Address 69","col4":{"data":"col4 data","value":"col4 value"}},
        {"code":"010","name":"Name 10","addr":"Address 78","col4":{"data":"col4 data","value":"col4 value"}}
]

旨在在两个不同的列中显示col4的数据和值。因此在treegrid表定义中添加了以下内容。

{field:'col4',title:'Col41 data',width:150,rowspan:2,formatter:function (value,row,index){return value["data"];}},
{field:'col4',title:'Col41 value',width:150,rowspan:2,formatter:function (value,row,index){return value["value"];}}

预计它可以工作但格式化程序只能看到数据字段。第二个格式化程序从不适用于该列。

有没有人知道任何可用的解决方法?

1 个答案:

答案 0 :(得分:0)

你应该更改字段的名称... jesasyui将字段名称与发送的json匹配并添加相应的值..因为你的字段名称对于它们追加相应对象的两个列都是相同的。

试试这个

{field:'col4_data',title:'Col41 data',width:150,rowspan:2,formatter:function (value,row,index){return row.col4["data"];}},
{field:'col4_value',title:'Col41 value',width:150,rowspan:2,formatter:function (value,row,index){return row.col4["value"];}}