easyui-combobox的案例

http://www.jeasyui.com/documentation/combobox.php

ComboBox

Extend from $.fn.combo.defaults. Override defaults with $.fn.combobox.defaults.

The combobox display a editable text box and drop-down list, from which the user can select one or multiple values.The user can type text directly into the top of list, or select one or more of present values from the list.

Dependencies
  • combo
Usage Example

Create combobox from <select> element with a pre-defined structure.

  1. <select id="cc" class="easyui-combobox" name="dept" style="width:200px;">  
  2.     <option value="aa">aitem1</option>  
  3.     <option>bitem2</option>  
  4.     <option>bitem3</option>  
  5.     <option>ditem4</option>  
  6.     <option>eitem5</option>  
  7. </select>  

Create combobox from <input> markup.

  1. <input id="cc" class="easyui-combobox" name="dept"  
  2.     data-options="valueField:'id',textField:'text',url:'get_data.php'" />  

Create combobox using javascript.

  1. <input id="cc" name="dept" value="aa">  
  1. $('#cc').combobox({  
  2.     url:'combobox_data.json',  
  3.     valueField:'id',  
  4.     textField:'text'  
  5. });  

Create two dependent comboboxes.

  1. <input id="cc1" class="easyui-combobox" data-options="  
  2.         valueField: 'id',  
  3.         textField: 'text',  
  4.         url: 'get_data1.php',  
  5.         onSelect: function(rec){  
  6.             var url = 'get_data2.php?id='+rec.id;  
  7.             $('#cc2').combobox('reload', url);  
  8.         }" />  
  9. <input id="cc2" class="easyui-combobox" data-options="valueField:'id',textField:'text'" />  

The json data format sample:

  1. [{  
  2.     "id":1,  
  3.     "text":"text1"  
  4. },{  
  5.     "id":2,  
  6.     "text":"text2"  
  7. },{  
  8.     "id":3,  
  9.     "text":"text3",  
  10.     "selected":true  
  11. },{  
  12.     "id":4,  
  13.     "text":"text4"  
  14. },{  
  15.     "id":5,  
  16.     "text":"text5"  
  17. }]  

Properties

The properties extend from combo, below is the added properties for combobox.

NameTypeDescriptionDefault
valueFieldstringThe underlying data value name to bind to this ComboBox.value
textFieldstringThe underlying data field name to bind to this ComboBox.text
modestringDefines how to load list data when text changed.Set to 'remote' if the combobox loads from server.When set to 'remote' mode, what the user types will be sent as the http request parameter named 'q' to server to retrieve the new data.local
urlstringA URL to load list data from remote.null
methodstringThe http method to retrieve data.post
dataarrayThe list data to be loaded.

Code example:

<input class="easyui-combobox" data-options="
		valueField: 'label',
		textField: 'value',
		data: [{
			label: 'java',
			value: 'Java'
		},{
			label: 'perl',
			value: 'Perl'
		},{
			label: 'ruby',
			value: 'Ruby'
		}]" />
null
filterfunctionDefines how to filter the local data when 'mode' is set to 'local'. The function takes two parameters:
q: the user typed text.
row: the list row data.
Return true to allow the row to be displayed.

Code example:

$('#cc').combobox({
	filter: function(q, row){
		var opts = $(this).combobox('options');
		return row[opts.textField].indexOf(q) == 0;
	}
});
 
formatterfunctionDefineds how to render the row. The function takes one parameter: row.

Code example:

$('#cc').combobox({
	formatter: function(row){
		var opts = $(this).combobox('options');
		return row[opts.textField];
	}
});
 
loaderfunction(param,success,error)Defines how to load data from remote server. Return false can abort this action.This function takes following parameters:
param: the parameter object to pass to remote server.
success(data): the callback function that will be called when retrieve data successfully.
error(): the callback function that will be called when failed to retrieve data.
json loader

Events

The events extend from combo, below is the added events for combobox.

NameParametersDescription
onBeforeLoadparamFires before a request is made to load data, return false to cancel this load action.

Code example:

// change the http request parameters before load data from server
$('#cc').combobox({
	onBeforeLoad: function(param){
		param.id = 2;
		param.language = 'js';
	}
});
onLoadSuccessnoneFires when remote data is loaded successfully.
onLoadErrornoneFires when remote data load error.
onSelectrecordFires when user select a list item.
onUnselectrecordFires when user unselect a list item.

Methods

The methods extend from combo, below is the added or overridden methods for combobox.

NameParameterDescription
optionsnoneReturn the options object.
getDatanoneReturn the loaded data.
loadDatadataLoad the locale list data.
reloadurlRequest the remote list data. Pass the 'url' parameter to override the original URL value.

Code example:

$('#cc').combobox('reload');  // reload list data using old URL
$('#cc').combobox('reload','get_data.php');  // reload list data using new URL
setValuesvaluesSet the combobox value array.

Code example:

$('#cc').combobox('setValues', ['001','002']);
setValuevalueSet the combobox value.

Code example:

$('#cc').combobox('setValue', '001');
clearnoneClear the combobox value.
selectvalueSelect the specified item.
unselectvalueUnselect the specified item.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值