【发布时间】:2018-11-27 13:18:34
【问题描述】:
我已经修改了一个现有的 Javascript 函数,以允许我填充多个 Jqgrid 下拉过滤器。代码是:
jQuery("#jQGridDemo").jqGrid({
url: 'http://localhost:58404/JQGridHandler.ashx',
datatype: "json",
colNames: ['Property ID', 'Property Ref', 'Short Address', 'Scheme Code', 'Scheme Name'],
colModel: [
{ name: 'PropertyID', index: 'PropertyID', width: 70, align: "left", stype: 'text', sortable: true},
{ name: 'PropertyRef', index: 'PropertyRef', width: 75, align: "left", stype: 'text', sortable: true},
{ name: 'ShortAddress', index: 'ShortAddress', width: 200, align: "center", sortable: true},
{ name: 'SchemeCode', index: 'SchemeCode', width: 80, align: "center", sortable: true },
{ name: 'SchemeName', index: 'SchemeName', width: 80, align: "center", sortable: true },
{name: 'PropertyType',width: 80},
],
beforeProcessing: function (data) {
getDropDownValues(data, "PropertyType")
}
.jqGrid('destroyFilterToolbar')
.jqGrid('filterToolbar', {
stringResult: true,
searchOnEnter: false,
defaultSearch: "cn"
});
}
function getDropDownValues(data, columnName) {
var propertyMap = {}, propertyValues = ":All", rows = data, i, symbol;
for (i = 0; i < rows.length; i++) {
symbol = rows[i].columnName;
if (!propertyMap.hasOwnProperty(symbol)) {
propertyMap[symbol] = 1;
propertyValues += ";" + symbol + ":" + symbol;
}
}
$(this).jqGrid("setColProp", 'columnName', {
stype: "select",
searchoptions: {
value: propertyValues
}
})
}
但是,在 Json 数据中找不到提供的列名(“PropertyType”),即使它存在。原始函数具有明确提到的列名并且有效:
symbol = rows[i].PropertyType;
有人知道我应该如何引用作为变量提供而不是明确提及的列名吗?
样本数据:
[{"PropertyID":1,"PropertyRef":"1","ShortAddress":"99 ROCK LANE,BODMIN,PL91 1NR","SchemeCode":"700000","SchemeName":"LODMIN","PropertyType":"HOU"}
谢谢
【问题讨论】:
-
请发布您的完整 jqGrid 设置和响应中的一些演示数据以获得帮助
-
我已经更新了原帖。
标签: javascript json jqgrid