当前,我正在使用select
选择从数据库检索的选项。但是我想提供另一种选择,用户可以在没有所需选项的情况下输入输入内容。
<div class="form-group">
<label for="createAppointmentContact" class="col-sm-2 control-label">Customer Name</label>
<div class="col-sm-10">
<select class="form-control select2contact" id="createAppointmentContact" onchange="showOptions(this)"></select>
</div>
</div>
从数据库获取选项的ajax
$(".select2contact").select2({
width: '100%',
theme: 'bootstrap',
allowClear: true,
cache: true,
multiple: false,
minimumInputLength: 0,
placeholder: '- Please Select -',
ajax: {
url: "../WS/wsCustomerDetails.asmx/GetCustomerDetailsList",
dataType: 'json',
delay: 200,
data: function (params) {
return {
searchKey: params.term || '',
page: params.page || 1,
pageLimit: 10,
userID: getCookie('UserID')
};
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: data.morePages
}
}
}
}
});
SQL查询
sqlQuery = string.Format(@"
SELECT TotalCount = COUNT(Contact_ID) OVER(),
Contact_ID AS id, Contact_Name AS text
FROM CustomerDetails
WHERE IsDelete = 0 AND Contact_Name is not null {0}
ORDER BY Contact_ID
OFFSET " + (Convert.ToInt32(page) - 1).ToString() + "*" + pageLimit + " ROWS FETCH NEXT " + pageLimit + " ROWS ONLY", sqlSearch);
是否可以在数据列表中使用select2?如何使用?如果没有,如何将选项从数据库获取到数据列表,然后将所选选项插入数据库?
答案 0 :(得分:0)
您正在寻找tagging或动态选项创建。这样可以轻松启用标记:
<select class="form-control">
<option selected="selected">orange</option>
<option>white</option>
<option>purple</option>
</select>
$(".js-example-tags").select2({
tags: true
});