將字符串複製並粘貼到p-autoComplete對我來說工作正常。我只是想分享我的方法,希望你能找到點亮的方法。
HTML:
<p-autoComplete [style]="{'width':'100%'}" name="searchSuggestions"
[(ngModel)]="suggestion" (completeMethod)="searchSuggestions(suggestion)"
[suggestions]="searchSuggestionsResult" field="field">
</p-autoComplete>
請注意,我傳遞的模式,以completeMethod作爲參數。
OH中,我使用的打字稿對角2
TS方式:
searchSuggestions(suggestion) {
this.searchSuggestionsResult = [];
if(suggestion != "") {
var list = this.searchSuggestionsResult.filter(function(el) {
return (el) ? el.toLowerCase().startsWith(suggestion.toLowerCase()) : false;
});
list.sort((a,b) => a.toLowerCase().localCompare(b.toLowerCase());
list.forEach(element => {
this.searchSuggestionsResult.push(element);
});
} else {
this.searchSuggestionsResult = [];
}
}
希望它能幫助!
我敢肯定,如果您正在粘貼文本,它不會註冊爲「選擇」事件,因爲您實際上沒有使用自動完成功能您描述的複製和粘貼的用例更適合到: '' –
我需要自動建議@David – Veera