我有一個看起來像這樣的檔案集合:
name: string;
address: IAddress;
tests: Item[];
rating?: number;
photo?: string;
每個檔案都有一個名稱作為 ID,每個檔案內部都有一個 Item 陣列, Item 是一個形狀物件:
export type Item = {
title: string;
price: number;
};
現在我有一個單獨的集合 i,其中有一個專案的最低和最高價格欄位,我需要搜索上述集合和里面的物件陣列以找到專案的最低和最高價格。我該怎么做?我正在嘗試這樣
const q = query(
collection(firestore, "stores"),
where("item.title", "==", this.title),
orderBy("item.price")
);
我剛剛意識到這不僅僅是 item.title,而是一個陣列,所以它是 item[x].title。如何在陣列中搜索它?謝謝
uj5u.com熱心網友回復:
無法在一組檔案中搜索陣列中價格最低的檔案。
您需要在檔案中添加一個欄位,該欄位從陣列中捕獲最低價格(例如item.lowestprice),然后在查詢中使用它:
const q = query(
collection(firestore, "stores"),
where("item.title", "==", this.title),
orderBy("item.lowestprice"), // ??
limit(1) // ??
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422633.html
標籤:
上一篇:不使用<Text>標簽的輸出變數
下一篇:從陣列中一一輸出變數
