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>//綁定到下拉列表框中顯示的值 } }}, ]],