脚本:
1 2 |
|
样式:
1 |
|
定义你的autocompleter:
1 2 3 |
|
或用于本地JSON来源:
1 2 3 4 5 6 7 8 |
|
如果你不会在源对象定义了一个值,标签将被用作后选择在输入字段的默认值。
方法:
插件后更改选项的定义:
1 |
|
例如:
1 2 3 4 |
|
开放列表:
1 |
|
关闭页面:
1 |
|
摧毁插件:
1 |
|
清除所有缓存:
1 |
|
设置默认值:
1 2 3 |
|
例如:
Autocompleter第一名称输入缓存,匹配强调限制和5的结果。
形式:
1 2 3 4 5 6 |
|
JavaScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
主要结构:
1 2 3 4 5 6 7 |
|
实例:使用在Angular2客户端
size:any=0;
ngAfterViewInit() {
let thiss=this;
$('#autocomplete-ajax').autocomplete({
minChars:2,
lookup: function (query,done){
thiss.getProject(query, function () {
debugger;
if (thiss.rootList && thiss.rootList.length > 0 ) {
thiss.size=0;
thiss.tempurl=thiss.route.url
.map(s=>s)
let path=thiss.tempurl.source._value[0].path;
if(path!='qiyefengxian'){
thiss.List=[];
}
var result = {
suggestions: thiss.List
};
done(result)
}else{
thiss.size=1;
thiss.id='';
thiss.List=[];
var result = {
suggestions: thiss.List
};
done(result)
}
});
},
autoFill:true,
cacheLength:1,
matchContains: true,
onSelect: function (data) {
console.log("data",data)
thiss.rootEntity.gsName=data.value;
thiss.id=data.data;
thiss.find();//查询一条数据的方法
}
});
}
//根据名称模糊查询
getProject(name:any,callback: any):any{
let contion:any={
name:name
}
console.log("name",name)
this.httpService.find("Controller/selectName2",contion).then((response)=>{
if(response.json().data==null){
return false;
}
this.List=response.json().data;
if (typeof callback == "function") {
callback();
}
})
}
后台的查询结果,List<ResultEntity >
public class ResultEntity implements Serializable{
private String value;
private String data;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public String toString() {
return "ResultEntity [value=" + value + ", data=" + data + "]";
}
}