[英]ListView React native cloneWithRows is not getting proper data
I am trying to pass the data from one screen to another and I have data in 我正在尝试将数据从一个屏幕传递到另一屏幕,并且我有数据
this.props.data which has something like this ["12121","434536"], I am trying to do the following trying to add that data to list via this.ds.cloneWithRows([values])
, this.props.data具有类似[[12121“,” 434536“]的内容,我正在尝试执行以下操作,以尝试通过
this.ds.cloneWithRows([values])
将数据添加到列表中,
but I am getting output like below: 但我得到如下输出:
["12121","434536"]
in one row, its not adding the elements one after another. ["12121","434536"]
排在一行中,它没有一个接一个地添加元素。
let values= [];
values =this.props.data;
alert(values)
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: this.ds.cloneWithRows([values]),
<ListView
style={{width: '100%'}}
renderHeader={() => <Text style={styles.text}>adding Started</Text>}
dataSource={this.state.dataSource}
renderRow={(rowData) => <View style={{borderWidth:1, borderColor: '#232C46',borderRadius: 4}}>
<Text style={[styles.text, {backgroundColor: '#192034'}]}>{rowData}</Text>
</View>
}
/>
Agreed, with the first answer, it's a syntax error ("values" is already in the correct form, no need to put it in an array). 同意,第一个答案是语法错误(“ values”已经采用正确的格式,无需将其放入数组中)。
Also, just FYI, ListView is a deprecated component and you may want to convert this into a FlatList for fewer bugs, better performance / memory usage, and I think a more intuitive API. 同样,仅供参考,ListView是一个已弃用的组件,您可能希望将其转换为FlatList,以减少错误,提高性能/内存使用率,并且我认为API更直观。
https://facebook.github.io/react-native/docs/flatlist https://facebook.github.io/react-native/docs/flatlist
Your data is already an array. 您的数据已经是一个数组。 You don't need the extra
[]
您不需要额外的
[]
Change it like below; 如下更改它;
this.ds.cloneWithRows(values)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.