文本框根据关键字异步搜索内容

$(_this).autocomplete({
    //定义要使用的数据,必须指定。
source: function (request, response) {
if ($(_this).val() == null || $(_this).val() == "") {
return;
}
$.ajax({
url: url,
method:"post",
dataType: "json",
data: {key: request.term},
success: function (data) {
response($.map(data, function (item) {
return {
label: item.name,
value: item.name,
id: item.id,
}
}));
}
});
},
minLength: 1,  //户必须输入的最小字符数
delay: 10,    //按键和执行搜索之间的延迟,以毫秒计
select: function(event, ui) {
this.value = ui.item.label;
$("#creditProductId").val(ui.item.id);
return false;
}
});

 

posted @ 2018-10-12 14:58  沟渠映明月  阅读(520)  评论(0编辑  收藏  举报