$("#serachCar").select2({
theme: "bootstrap",
placeholder: "Search for a repository",
minimumInputLength: 2,//最少输入多少个字符后开始查询
language: "zh-CN",
allowClear:true,
ajax: {
type:'GET',
url: "{:U('getVehiclePage')}",
dataType: 'json',
delay: 250,
data: function (params) {
return {
code: params.term, // search term 请求参数 , 请求框中输入的参数
page: params.page || 0,
size: 10,
};
},
processResults: function (data, params) {
params.page = params.page || 0;
return {
results: data.rows,//itemList
pagination: {
more: (params.page * 10) < data.total
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // 自定义格式化防止xss注入
templateResult: repoFormatResult, // omitted for brevity, see the source of this page
templateSelection: repoFormatSelection,
});
function repoFormatResult(repo) {
if (repo == undefined || repo.loading == true) {
return '<table class="table table-bordered" style="padding: 0;margin: 0">' +
'<tr><td>车牌</td><td>车型</td><td>车主</td><td>手机号</td><td>门店</td></tr></table>';
} else {
return '<table class="table table-bordered" style="padding: 0;margin: 0">' +
'<tr><td width="20%">'+repo.registerno+'</td><td width="20%" >'+repo.cmodel+'</td><td width="20%">'+repo.driver+'</td><td width="20%">'+repo.driverhandphone+'</td><td width="20%">'+repo.comno+'</td></tr></table>';
}
}
function repoFormatSelection(repo) {
if (repo.registerno) {
vehicleData = repo; //赋值给当前车辆档案
saveMember(repo.driverhandphone);
return repo.registerno;
}
}
保存的对象 没法表单提交
delete vehicleData.element;
设置多选例子
$(".notify").select2({
theme: "bootstrap",
tags:["开单","结算","收银","回访","保险",]
});
multiple="multiple" //加上这属性 select
网友评论