DIV CSS 佈局教程網

jQuery EasyUI 的 ComboBox 下拉組合框:屬性、事件與方法完整說明
編輯:JQuery特效代碼     

ComboBox 擴充自 $.fn.combo.defaults,並以 $.fn.combobox.defaults 覆寫預設值。

相依元件:combo

用法

可以直接改寫原生 select,也可以指定一個 input:

<select id="cc" name="dept" style="width:200px;">
    <option value="aa">aitem1</option>
    <option>bitem2</option>
    <option>bitem3</option>
</select>

$('#cc').combobox({
    url: 'combobox_data.json',
    valueField: 'id',
    textField: 'text'
});

對應的 JSON 資料格式如下,其中 selected 為 true 的項目會成為初始選取值:

[
    { "id": 1, "text": "text1" },
    { "id": 2, "text": "text2" },
    { "id": 3, "text": "text3", "selected": true },
    { "id": 4, "text": "text4" }
]

屬性

屬性沿用 combo,以下為 combobox 新增的部分:

名稱類型說明預設值
valueFieldstring對應到 combobox 值的資料欄位名稱。value
textFieldstring對應到顯示文字的資料欄位名稱。text
modestring文字變動時如何載入列表資料。若資料來自伺服器端篩選,應設為 'remote'。local
urlstring從遠端載入列表資料的網址。null
methodstring取得資料使用的 HTTP 方法。post
dataarray直接載入的列表資料。null
filterfunction當 mode 為 local 時決定如何篩選。參數為 q(使用者輸入文字)與 row(該列資料),回傳 true 表示顯示該列。無
formatterfunction自訂每一列的呈現方式,參數為 row。無

filter 的常見應用是做不分大小寫、忽略空白的模糊比對:

filter: function(q, row){
    var val = q.toLowerCase();
    return row.text.toLowerCase().indexOf(val) > -1;
}

事件

名稱參數說明
onLoadSuccessnone遠端資料載入成功時觸發。
onLoadErrornone遠端資料載入失敗時觸發。
onSelectrecord使用者選取某個列表項時觸發。
onUnselectrecord使用者取消選取時觸發。

方法

名稱參數說明
optionsnone回傳設定物件。
getDatanone回傳已載入的資料。
loadDatadata載入本地列表資料。
reloadurl重新向遠端請求列表資料。
setValuesvalues以陣列設定多個值。
setValuevalue設定單一值。
clearnone清除選取值。
selectvalue選取指定值的選項。
unselectvalue取消選取指定值的選項。

資料量龐大時(例如數萬筆的產品清單),建議把 mode 設為 remote,並搭配 onSelect 或輸入事件觸發 reload,只取回符合條件的部分,避免一次把全部資料塞進瀏覽器。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved