Select2 uses jQuery’s $.ajax function to execute the remote call by default. An alternative transport function can be specified in the ajax settings,or an entirely custom implementation can be built by providing a custom query function instead of using the ajax helper.
但是我找不到有关如何做的例子.
Select2允许通过更改ajax.transport选项来使用不同的AJAX传输.
在3.5.2中,这必须是一个$.ajax兼容的方法,所以它必须能够获取包含成功和失败回调的对象.
$("select").select2({
ajax: {
transport: function (args) {
// args.success is a callback
// args.failure is a callback
// should return an object which has an `abort` method.
return $.ajax(args);
}
}
});@H_403_7@
在4.0.0中,这必须是一个接受params对象(同一个传递给ajax.data),成功回调和失败回调的方法.
$("select").select2({
ajax: {
transport: function (params,success,failure) {
var $request = $.ajax(params);
$request.then(success);
$request.fail(failure);
return $request;
}
}
});@H_403_7@