如果我添加了諸如“?????”、“?????”之類的字串或任何其他字串值,我只能從陣列中獲取我需要的值,但是我希望將值從另一個組件或螢屏傳遞給一個道具。有沒有辦法處理這個問題。

const fetchCategoryProducts = (catId)=>{
const categoryProductsCollection = query(collection(db, "Product"), where("categories", "array-contains", catId))
const getCategoryProducts = getDocs(categoryProductsCollection);
const categoryProducts = (await getCategoryProducts).docs.map(item=>{
const data = item.data();
data.id = item.id;
return data
})
console.log(categoryProducts) // getting empty array here
}}
uj5u.com熱心網友回復:
根據我的問題:
的價值是
catId多少?
而你的回答:
字串的值是陣列中包含的值之一。我只用字串而
catId不是catId.
如果代碼使用硬編碼的值,那么資料庫中的值很可能包含一些空格,為此,您必須使用trim():
const fetchCategoryProducts = (catId)=>{
const categoryProductsCollection = query(collection(db, "Product"), where("categories", "array-contains", catId.trim()))
const getCategoryProducts = getDocs(categoryProductsCollection);
const categoryProducts = (await getCategoryProducts).docs.map(item=>{
const data = item.data();
data.id = item.id;
return data
})
console.log(categoryProducts)
}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/528290.html
