-1
search(event) {
this.autocompletedata.forEach((entry) => {
if (this.showFilter === '1') {
this.results = entry['items'].filter(a => a['item'] ? a['item'].startsWith(event.query) : false);
} else if (this.showFilter === '2') {
this.results = entry['items'].filter(a => a['service'] ? a['service'].startsWith(event.query) : false);
} else {
this.results = entry['items'].filter(a => a['phoneNum'] ? a['phoneNum'].startsWith(event.query) : false);
}
});
}
我有一個問題,當我使用startWith。即時得到這個錯誤:無法讀取未定義的屬性'startsWith'?
Cannot read property 'startsWith' of undefined
我array
內array
。因此,即時通訊foreach
第一陣列和裏面我找到項目array
。 items
我有財產item
。現在即時通訊使用自動完成,所以當我進入測試,以獲得測試所有數據。任何建議什麼即時做錯了?
這意味着在本質上那是什麼的一個或全部在'項中的項目[「項目」]的'是不確定的匹配濾波器,無論是你的'一[ 'item']','a ['service']'或'a ['phoneNum']'?可能有所幫助的不是調用'startsWith()'將print ['items']'和所有過濾的項目打印到控制檯,以調試實際接收預期項目的開始。 – Nope
@Fran這也是我的第一個想法。但是他通過使用'a''item']檢查條目是否存在?一個['item']。startsWith()...',所以這個錯誤不應該發生。最後我會建議主要是一樣的。將你的lambda擴展到一個函數體(在胖箭頭後面使用花括號)並添加一個'console.log()'(或'debugger;'),可能被一個if語句包圍,這取決於你需要找到多少條目原因。 – Oliver
這就是它tnx :) – None