【发布时间】:2017-09-28 03:17:55
【问题描述】:
我确实有一个带有renderRow() 函数的 ListView 组件。我的自定义 ListBountiesView 组件呈现 ListView Row 还采用名为 cr 的道具,并根据 cr 的值在每一行中显示一些内容。
问题是当this.props.customerRelationship 改变它的值时,ListView 行没有得到更新。
我正在这样做:this.props.customerRelationship.points += responseJson.points;
我猜ListView 仅在data 属性更改时更新,但我怎样才能将道具移动到我的 renderRow 组件以便它们也更新 ListView?
SuperScreen.js
renderRow(bounty) {
const { customerRelationship } = this.props;
return (
<ListBountiesView
key={bounty.id}
bounty={bounty}
cr={customerRelationship}
onPress={this.openDetailsScreen}
/>
);
}
render() {
const { bounties } = this.props;
return (
<ListView
data={bounties}
renderRow={this.renderRow}
loading={loading}
/>
)
【问题讨论】:
-
您不会在任何地方更新您的
dataSource,这就是它不会改变的原因。正如其他人所建议的那样,您需要使用其他生命周期事件来捕获更改。或者,您可以考虑使用FlatList,它不需要您设置dataSource对象并且只需要一个数组 - 这样当您的道具更改时它会自动更新。
标签: react-native react-native-listview shoutem