【发布时间】:2018-03-18 00:20:30
【问题描述】:
如何使用 axios React Native 访问数组中的数据,并按类别分隔列表
我正在尝试在 react native 中使用 axio 部署包含类别和产品的列表
我的 json 结构
[
{
"id": "1",
"name": "TV",
"list": [
{
"idp": "1",
"namep": "TV 43"
},
{
"idp": "2",
"namep": "TV 32"
}
]
},
{
"id": "2",
"name": "Couch",
"list": [
{
"idp": "3",
"namep": "Couch for 3 people"
},
{
"idp": "4",
"namep": "Couch for 2 people"
}
]
}
]
我已经做了什么,所以我可以显示类别
constructor(props) {
super(props);
this.state = { category: [], list: [] };
}
componentWillMount() {
axios.get('http://localhost/api/list.json')
.then(response => {
this.setState({
category: response.data,
list: response.data.list });
})
.catch(() => { console.log('Err'); });
}
.............
{this.state.category.map((item, i) => {
<Text>{item.name}</Text>
{ item.list.map((product, i) => {
<Text>{product.namep}</Text>
})}
})}
【问题讨论】:
-
“拆分列表”是什么意思?
-
访问数组中的数据,并按类别分隔列表@Oxcarga
标签: javascript react-native axios