【发布时间】:2021-01-21 08:54:44
【问题描述】:
我从后端获取这些数组
{_id: "6006a53cfc8d582e88f26bda",…}
address: "194/24,Magalegoda,Veyangoda"
mobile: "+94774335548"
name: "Gayath Sandarge"
orders: [{_id: "6006a511fc8d582e88f26bd8", product_name: "highland fresh milk", product_brand: "Highland",…},…]
0: {_id: "6006a511fc8d582e88f26bd8", product_name: "highland fresh milk", product_brand: "Highland",…}
product_brand: "Highland"
product_category: "fresh milk"
product_name: "highland fresh milk"
product_price: "100"
quantity: "3"
_id: "6006a511fc8d582e88f26bd8"
1: {_id: "6006a519fc8d582e88f26bd9", product_name: "fbndxcfn", product_brand: "fdncn",…}
product_brand: "fdncn"
product_category: "fgncfggn"
product_name: "fbndxcfn"
product_price: "464"
quantity: "4"
token:
_id: "6006a519fc8d582e88f26bd9"
我的前端代码是
const ListBar = (props) => { 返回(
<div className='product-card container'>
<div>
<p className='product-card label'>{props.product.name}</p>
<p className='product-card label'>{props.product.address}</p>
<p className='product-card label'>{props.product.mobile}</p>
<ul>
<li className='product-card label'>{props.product.orders[]}</li>
<li className='product-card label'>{props.product.orders[]}</li>
</ul>
</div>
</div>
);
}
常量存储 = () => { const [listData, setListData] = useState({ lists: []});
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'http://localhost:4000/store/admin/orders'
);
setListData({ lists: result.data });
};
fetchData();
}, []);
return (
<div className="store">
<div class="header">
<a href="/store" class="logo">Milk.Lk</a>
<div className="menu">
<div class="dropdown">
<button class="dropbtn">Category</button>
<div class="dropdown-content">
<a href="/freshmilk">FreshMilk</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<a href="/login">Contact us</a>
</div>
<div class="header-right">
<a href="/register">SingUp</a>
<a href="/login">Login</a>
</div>
</div>
<div class="container">
<div class="cards">
{listData.lists.map((current, i) => (
<ListBar product={current} key={i} />
))}
</div>
</div>
</div>
);
}
导出默认存储;
我能否获得一些帮助以获取订单数组详细信息以及其他详细信息。名称、地址和手机显示正确,但详细信息无法打印
【问题讨论】:
-
- {props.product.orders[]}
- {props.product.orders[ ]}
将需要的索引传入括号中,orders 是需要映射的数组。如果您不知道索引,那么您将不得不以某种方式定位它。