React-Native业余爱好者在这里,我写了一个php api来从MySQL服务器中检索数据,并且我需要将它放入ListView以显示在应用程序中。从JSON数据填充React-Native ListView
用于显示该代码是:
constructor(props) {
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
this.state = {
dataSource: ds.cloneWithRows(this.props.response)
};
}
renderRow(rowData) {
return (
<View style={styles.row}>
<Text>{response}</Text>
</View>
)
}
render() {
return {
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}/>
);
}
}
和API JSON回报如下:
[{"barcode":"50201600","name":"Cadbury's Creme
Egg","tescoPrice":"1","sainsburysPrice":"1","asdaPrice":"1"},
{"barcode":"5034660520191","name":"Cadburys Twirl 4
Pack","tescoPrice":"1","sainsburysPrice":"1","asdaPrice":"1"}]
我得到的错误是:Objects are not valid as a React child (found: object with keys {barcode, name, tescoPrice, sainsburysPrice, asdaPrice}). If you meant to render a collection of children, use an array instead. Check the render method of 'Text'
有什么建议吗?
干杯
问题是什么?你有什么尝试?有没有错误信息?我们不在这里为你做你的功课... – c4k
@ c4k我指定了我需要做的问题形式。我需要将来自API的json数据返回到列表视图中以显示产品。 所示的错误消息是“对象是不是一个做出反应的孩子有效(发现:与键{条码,名称,tescoPrice,sainsburysPrice,asdaPrice}对象)! 这不是功课,这是一个个人项目谢谢:) –
什么如果你改变' {response} '到' {response.name} '例如? –
c4k