the code :
<div class="col-xs-7">
<select class="js-data-example-ajax form-group col-xs-12">
</select>
</div>
<script type="text/javascript">
var formatRepo =function (repo){
if (repo.loading) return repo.text;
var markup =
repo.name +'-'+repo.natrualkey;
return markup;
}
var formatRepoSelection =function (repo){
return
repo.name||repo.natrualkey;
}
$(function () {
$('.js-data-example-ajax').select2({
// placeholder:"选择供应商...",
// multiple: true,
ajax: {
url: "../../../system/customer/select",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page:
params.page
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page =
params.page || 1;
return {
results: data.items,
pagination: {
more: (
params.page * 30) < data.total_count
}
};
}
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo,
templateSelection: formatRepoSelection
});
})
</script>