我正在从网络服务中提取一些数据。 在返回 JSON 数组的调用中,我可以很好地执行以下操作。
WebServiceHandler.get('http:/api.local/stock',{},{)
.then((val)=>{
this.setState({
dataSource: this.state.dataSource.cloneWithRows(val)
})
})
.catch((error) => console.log('callapi:'+ JSON.stringify(error)));
}
例如以下数据将完美地工作..
[
"SKU1",
"SKU2",
"SKU3"
]
但是,当我尝试使用如下键输入对象时,它不喜欢它。
{
"SKU1": {"level":11, "description":"This is SKU 1"},
"SKU2": {"level":22, "description":"This is SKU 2"},
"SKU3": {"level":33, "description":"This is SKU 3"}
}
ListView 可以处理带键的对象吗?还是我需要循环并修改收到的数据才能将其传递给 ListView?
如果我必须修改它,而不是循环它,是否有任何框架提供了实现此目的的快速方法?
最佳答案
你不能给 cloneWithRows 对象。您可以转换为数组,也可以使用 cloneWithRowsAndSections。它接受对象,您也可以呈现 sectionHeader。
检查文档 -> https://facebook.github.io/react-native/docs/listviewdatasource.html
关于javascript - React Native - ListView,CloneWithRow,对象不是数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40389592/