1.绑定固定的值数据库
<span style="font-family:Microsoft YaHei;"> $(function () { /**管道级别*/ var pipingLevel = [{"value":"1","text":"A级"},{"value":"2","text":"B级"},{"value":"3","text":"C级"}];//json格式 function levelformmat(value){ if(value==0){ return ; } for(var i =0;i<pipingLevel.length;i++){ if(pipingLevel[i].value==value){ return pipingLevel[i].text; } } } $("#datagrid").datagrid({ singleSelect: true, fitColumns: false, border: false, columns: [[ {field: 'number', title: '编号', width: 66, editor: "text"}, {field: 'pipingNo', title: '管道编号', width: 90, editor: "text"}, {field: 'pipingName', title: '管道名称(登记单元)', width: 170, editor: "text"}, {field: 'pipingLevel', title: '管道级别', width: 100, editor:{ type: '<strong>combobox</strong>', options: { data: pipingLevel, valueField: "value", textField: "text", editable: false, panelHeight:70, required: true } }}, ]], </span> });
2.从远程获取数据,而后绑定到combobox中json
columns: [[ {field: 'number', title: '编号', width: 100, editor:'text'}, {field: 'pipingNo', title: '管道编号', width: 100, editor: "text"}, {field: 'pipingName', title: '管道名称(登记单元)', width: 300, editor: "text"}, {field: 'DesignUnit', title: '设计单位', width: 300,editor:{ type:'combobox', options:{ url: 'pressurePipingUnit/unit2',<span style="white-space:pre"> </span>//重远程加载数据 panelHeight: '200', valueField:'unitId',<span style="white-space:pre"> </span>//保存到数据库的值 textField:'unitName',<span style="white-space:pre"> </span>//绑定到下拉列表框中显示的值 } }}, ]],