我有一个iOS应用程序,我正在使用react-native.Game类包含一个ListView组件.我在构造函数中设置状态并包含一个dataSource.我现在有一个硬编码的数据数组,我存储在不同的state属性(this.state.ds)中.然后在componentDidMount我使用该cloneWithRows方法克隆我this.state.ds作为我的视图的dataSource.就ListViews来说,这是非常标准的并且运行良好.这是代码:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require("react-native");
var { StyleSheet, Text, View, ListView, TouchableHighlight } = React;
class Games extends React.Component {
constructor(props) {
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 != r2
});
this.state = {
ds: [
{ AwayTeam: "TeamA", HomeTeam: "TeamB", Selection: "AwayTeam" },
{ AwayTeam: "TeamC", HomeTeam: "TeamD", Selection: "HomeTeam" }
],
dataSource: …Run Code Online (Sandbox Code Playgroud) 我创建了一个使用a ListView来显示联系人列表的组件.单击一行时,我更新了state包含所有选定联系人的组件中的数组.但是,我没有将此数组用作dataSource我的ListView组件.
我想重新ListView修改此数组,以便显示所选联系人的图像.
以下是我目前情况的一个例子:
renderListView: function(){
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
style={styles.listView}
/>
}
renderRow:function(row){
return if(this.state.something === true) <Text>Something</Text>
else <Text>Something Else</Text>
}
Run Code Online (Sandbox Code Playgroud)
我试着打电话.forceUpdate(),它调用render方法而不是renderRow方法.
有什么建议吗?