使用 jqGrid 的自定义 JSON 格式
我有一个 JSON 文件,其格式必须如下。如何让 jqGrid 使用 jsonmap、colModel 或 jsonReader 选项解释此格式?
[
{
"element1" : {
"subElement1" : "value",
"subElement2" : "value"
}
"element2" : {
"subElement3" : "value",
"subElement4" : "value"
}
},
{
"element1" : {
"subElement1" : "value",
"subElement2" : "value"
}
"element2" : {
"subElement3" : "value",
"subElement4" : "value"
},
// . . . etc. . . .
}
]
colNames
将是 ["subElement1", "subElement2", "subElement3", "subElement4"]
。
非常感谢您的帮助。
I have a JSON file that must be formatted as follows. How can I have jqGrid interpret this format using the jsonmap
, colModel
, or jsonReader
options?
[
{
"element1" : {
"subElement1" : "value",
"subElement2" : "value"
}
"element2" : {
"subElement3" : "value",
"subElement4" : "value"
}
},
{
"element1" : {
"subElement1" : "value",
"subElement2" : "value"
}
"element2" : {
"subElement3" : "value",
"subElement4" : "value"
},
// . . . etc. . . .
}
]
colNames
will be ["subElement1", "subElement2", "subElement3", "subElement4"]
.
Thanks a lot for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以在此处阅读有关格式化的 jQGrid API:
http://www.trirand.com/jqgridwiki/doku.php?id =wiki:colmodel_options
考虑到您的值都是字符串,为您提供自定义格式化程序有点棘手...它也支持货币和日期排序。
演示在此处提供源代码: http://www.trirand.com/blog/jqgrid/ jqgrid.html
另外,非常确定您可以指定一个
函数
作为格式,并在该函数中返回格式化值。例如,我编写了一个函数,它接受一个状态并返回一个带有该状态图标的图像。这是一个例子:
You could always just read the jQGrid API on formatting here:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options
Kind of tricky to provide you with custom formatters considering your values are all strings... It supports sorting for curreny and dates as well.
The demos provide source code here: http://www.trirand.com/blog/jqgrid/jqgrid.html
Also, pretty sure you can just specify a
function
as the format and in that function return the formatted value. For example, I wrote a function that took a status and returned an image with an icon for that status.Here's an example: