使用BuildSelect方法在我的jqgrid的编辑弹出窗口中构建下拉列表。选择列表为每一行添加一个额外的空选项。空的是多余的,我无法弄清楚它来自哪里。
colModel: [
{ name: "GraftId", key: true, hidden: true },
{ name: "GraftYear", search: true, editable: true },
{ name: "GraftType", search: true, editable: true, edittype: "select",
editoptions: {
dataUrl: getTypesUrl,
buildSelect: function (response) {
var data = typeof response === "string" ? $.parseJSON(response) : response,
s = "<select>";
$.each(data, function () {
s += '<option value="' + this.GraftTypeId + '">' + this.GraftTypeName + '<option>';
})
return s + "</select>";
}
}
}
]
返回:
<select role="select" class="FormElement form-control" id="GraftType" name="GraftType" rowid="1">
<option value="1" role="option">Field Graft</option>
<option role="option"></option>
<option value="2" role="option">Field Graft/Barnes</option>
<option role="option"></option>
<option value="3" role="option">Field Graft/Larry</option>
<option role="option"></option>
<option value="4" role="option">Field Graft/Lisa</option>
<option role="option"></option>
<option value="5" role="option">Pot Graft</option>
<option role="option"></option>
</select>
json字符串看起来很好:
[{"GraftTypeId":1,"GraftTypeName":"Field Graft"},{"GraftTypeId":2,"GraftTypeName":"Field Graft/Barnes"},{"GraftTypeId":3,"GraftTypeName":"Field Graft/Larry"},{"GraftTypeId":4,"GraftTypeName":"Field Graft/Lisa"},{"GraftTypeId":5,"GraftTypeName":"Pot Graft"}]
答案 0 :(得分:0)
发现结束选项标签缺少斜线,所以应该是。一切都很好。