![](/img/trans.png)
[英]AttributeError: 'NoneType' object has no attribute 'get' despite dictionary being full
[英]How to get an array to stop being an object?
我有一個數組字段,在我的產品集合中稱為變體。 但是當我控制台記錄它時,它說它是 object,所以現在我無法 map 它。
我所做的是 map 使用 useEffect 獲取我的產品詳細信息的文檔
useEffect(() => {
const getProducts = async () => {
const q = query(
collection(db, "Products"),
where("slug", "==", router.query.slug)
);
const querySnapshot = await getDocs(q);
querySnapshot.docs.map((doc) => setProduct(doc.data()));
};
getProducts();
}, [router.query.slug]);
//Lets say we have an object
const obj1 = {calories: 300, price: 800, size: 'medium'};
const obj2 = {calories: 500, price: 1300, size: 'large'};
//Since you want to have two objects in your array, spread the two objects
const arr = [...obj1, ...obj2];
//arr becomes an array which you can now map
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.