我需要根據單詞搜索進行過濾,當我查找一個單詞時,它會提取出我需要的內容,但是在搜索滿足要求的多個單詞時,我遇到了一些麻煩。所以問題是,我需要保留之前的搜索并將第二個單詞的下一個結果添加到這個陣列中。
/* ===== Search images by keyword =====*/
searchByKeyword() {
if (this.searchText != "" && this.searchText != null) {
if (this?.plansBeforeSearch?.length == 0) {
this.plansBeforeSearch = this.selectedPlans;
}
this.searchTextDivision();
for (let i = 0; i < this.searchTextArray.length; i ) {
/* this.filteredImages = */
this.test[i] = this.planCollection
.filter(
(pl) =>
this.plansBeforeSearch.find((p) => p.name == pl.name) != null
)
.filter((plan: Plan) => {
return [
plan.id,
plan.code,
plan.name,
plan.gallery,
plan.tags,
plan.brand,
plan.description,
plan.width,
plan.depth,
plan.sqf,
plan.bedrooms,
].some((field) =>
field
?.toString()
?.toLowerCase()
?.includes(
this.searchTextArray[i].toString().toLowerCase().trim()
)
);
});
}
this.filteredImages = this.test[0];
console.log(this.test);
console.log(this.filteredImages);
}
}
我創建了一個我想要使用的單詞陣列,并且對于每個回圈,我將它們保存在這個測驗陣列中。它保留所有符合要求的影像
但是當我將它傳遞給顯示影像的過濾影像陣列時,我只能傳遞一個位置。所以在我分享的代碼中,我設定了第一個要顯示的位置,但我需要所有三個位置!
我想也許如果我將測驗陣列具有的所有陣列合并到一個只有一個位置的陣列中,我可以將其傳遞給filteredImages
uj5u.com熱心網友回復:
嘗試使用flat陣列:
this.filteredImages = this.test.flat()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/342607.html
標籤:javascript 打字稿 Vue.js
