<script src="/activities/js/jquery-1.11.0.min.js"></script>
<script src="/activities/js/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/activities/css/jquery-ui.min.css">
<script>
$(function(){
var banddata=[];
$( "#brandMsg" ).autocomplete({
source: function( request, response ) {
var a = [];
$.ajax({
type: "get",
url: '/activities/activity/getBrandMessage?brandName='+request.term,
dataType: "json",
async: false,
success: function( data ) {
banddata=data;
banddata.forEach(function(item){
a.push({
// 设置item信息
label: item.name, // 下拉项显示内容
value: item.name, // 下拉项对应数值
id: item.ID, //自定义字段
})
})
}
});
response(a)
},
minLength: 2, // 输入框字符个等于2时开始查询
select: function( event, ui ) { // 选中某项时执行的操作
// 存放选中选项的信息
$("#brandId").val(ui.item.id);
}
});
});
</script>
后台数据是一个json 数组
[{"hasShop":false,"iD":0,"keywordCount":0,"name":"1","shopCount":0},{"hasShop":false,"iD":58,"keyword":"","keywordCount":0,"name":"2","product":"","shopCount":0,"shopID":"","status":"1"}]