gpt4 book ai didi

javascript - 对 jqGrid 单元格数据使用键/值对

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:52:17 25 4
gpt4 key购买 nike

我有一个这样定义的 jqGrid:

$("#tableFeedbackReports").jqGrid({
url: '/FeedbackReports/GetFeedbackReport',
datatype: 'json',
colNames: ['ColA', 'ColB', 'ColC', 'ColD'],
colModel: [{ name: 'ColA', index: 'ColA', width: 60 },
{ name: 'ColB', index: 'ColB', width: 60 },
{ name: 'ColC', index: 'ColC', width: 60 },
{ name: 'ColD', index: 'ColD', width: 60 },
/* ... and so on */

现在,当 ajax 调用返回时,它必须返回一个数组,其中包含将进入每一行的内容。

['value', 'value', 'value']

是否可以让 jqGrid 接受行数据的键/值对?

[{ 'ColA' : 'value', 'ColB' : 'value', 'ColC' : 'value', 'ColD' : 'value'}]

那么当 jqGrid 加载数据时,它会自动将数据绑定(bind)到模型中的列?

最佳答案

查看 jqGrid Wiki 上的 jsonReader 选项,特别是它的 repeatitems 属性。从该页面:

The repeatitems element tells jqGrid that the information for the data in the row is repeatable - i.e. the elements have the same tag cell described in cell element. Setting this option to false instructs jqGrid to search elements in the json data by name. This is the name from colModel or the name described with the jsonmap option in colModel.

他们的例子是:

jQuery("#gridid").jqGrid({
...
jsonReader : {
root:"invdata",
page: "currpage",
total: "totalpages",
records: "totalrecords",
repeatitems: false,
id: "0"
},
...
});

它将处理以下格式的数据,带有键/值对:

{ 
totalpages: "xxx",
currpage: "yyy",
totalrecords: "zzz",
invdata : [
{invid:"1",invdate:"cell11", amount:"cell12", tax:"cell13", total:"1234", note:"somenote"},
{invid:"2",invdate:"cell21", amount:"cell22", tax:"cell23", total:"2345", note:"some note"},
...

]

关于javascript - 对 jqGrid 单元格数据使用键/值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2066781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com