gpt4 book ai didi

angular - ng2-completer 获取 selectedObject

转载 作者:行者123 更新时间:2023-12-04 19:44:21 27 4
gpt4 key购买 nike

如何在选定事件中获取 originalObject?

例如,在此代码中,我想使用值字段,但要搜索颜色!

protected searchData = [
{ color: 'red', value: '#f00' },
{ color: 'green', value: '#0f0' },
{ color: 'blue', value: '#00f' },
{ color: 'cyan', value: '#0ff' },
{ color: 'magenta', value: '#f0f' },
{ color: 'yellow', value: '#ff0' },
{ color: 'black', value: '#0' }
];

constructor(private completerService: CompleterService) {
this.dataService = completerService.local(this.searchData, 'color','color');
}

这是我的模板:

<ng2-completer [(ngModel)]="searchStr" [datasource]="dataService" 
[minSearchLength]="0">

谢谢。

最佳答案

<ng2-completer name="searchStr" [(ngModel)]="model.searchStr" [datasource]="dataService" [minSearchLength]="0" (selected)="onItemSelect($event)" #searchStr="ngModel"></ng2-completer>


export class .....Component{
model:any={};
...
... ..
...
onItemSelect(selected:CompleterItem){

if(selected)
this.model.searchStr = selected.originalObject.value;
}
}
}

关于angular - ng2-completer 获取 selectedObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44268120/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com