自动完成功能不起作用,第一次加载下拉列表,一旦我尝试输入某些内容没有过滤,那么下拉列表值就消失了 service.ts
getUserLocations(UserID: string, allList:string ) {
return this._http.get(environment.BASE_API_URL + 'xxxxx/' + ID + '/' + allList)
.map((response: Response) => response.json())
.do(data => console.log('locations ' + JSON.stringify(data)))
.catch(this.handleError);
}
组件.ts
brand: any [];
filteredBrands: any[];
GetUserLocations(PNSLUID: string, allList: string) {
this._searchService.getUserLocations(ID, allList)
.subscribe(
data => {
this.brand= data.result.name;//not sure how to bind the id
},
error => console.log('GetControls Method: ' + <any>error, 'alert alert-danger'));
}
filterBrands(event) {
this.filteredBrands = [];
for (let i = 0; i < this.brand.length; i++) {
let brand = this.brand[i];
if (brand.toLowerCase().indexOf(event.query.toLowerCase()) == 0) {
this.filteredBrands.push(brand);
}
}
}
html
<p-autoComplete [(ngModel)]="brand" [suggestions]="filteredBrands" (completeMethod)="filterBrands($event)" [size]="30"
[minLength]="1" placeholder="Office" [dropdown]="true">
<ng-template let-brand pTemplate="item">
<div class="ui-helper-clearfix" style="border-bottom:1px solid #D5D5D5">
<div style="font-size:18px;float:right;margin:10px 10px 0 0">{{brand}}</div>
</div>
</ng-template>
</p-autoComplete>
问题是它没有填充自动完成下拉列表..绑定有问题
*************************************************更新****************************************************** ***问题:示例:我的下拉列表具有以下值
a区
b区
c区
乙肝办公室
迪办公室
如果我键入区域自动完成不起作用,它仍然会显示所有值,但是,如果我选择区域 b 然后开始删除 b 然后自动完成工作..换句话说..它只有在我选择一个值但我开始时才有效从空文本开始输入它不起作用
html
<p-autoComplete name="OfficeList" [(ngModel)]="val" [suggestions]="results" (completeMethod)="search($event)" field="name" dataKey="id" [dropdown]="true"></p-autoComplete>
界面
export interface IOffices {
id: number,
name:string
}
零件
val: IOffices;
results: IOffices[];
originalResults: IOffices[];
GetUserLocations(PNSLUID: string, allList: string) {
this._searchService.getUserLocations(PNSLUID, allList)
.subscribe(
data => {
this.results = data.result;
this.originalResults = data.result;
},
error => console.log('GetControls Method: ' + <any>error, 'alert alert-danger'));
})
}
search(event) {
console.log("result 2 : " + this.originalResults.length.toString());
console.log("event : " + event.query.toString());
this.results = this.originalResults;
this.results = this.results.filter(data =>
data.name.indexOf(event.query) !== -1);
}