Mat*_*nja 1 javascript reactjs react-native
我从网络服务中提取一些数据.在返回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)));
}
Run Code Online (Sandbox Code Playgroud)
例如,以下数据将完美地工作..
[
"SKU1",
"SKU2",
"SKU3"
]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用下面的键来提供对象时,它不喜欢它.
{
"SKU1": {"level":11, "description":"This is SKU 1"},
"SKU2": {"level":22, "description":"This is SKU 2"},
"SKU3": {"level":33, "description":"This is SKU 3"}
}
Run Code Online (Sandbox Code Playgroud)
ListView可以用键处理对象,还是我需要在收据上循环和修改这些数据才能将它传递给ListView?
如果我必须修改它,而不循环它,任何框架是否提供了一个快速的方法来实现这一点?
你不能给cloneWithRows提供对象.您可以转换为数组,也可以使用cloneWithRowsAndSections.它接受对象,你也可以渲染sectionHeader.
检查文档 - > https://facebook.github.io/react-native/docs/listviewdatasource.html
| 归档时间: |
|
| 查看次数: |
1705 次 |
| 最近记录: |