我有一个TabBar为基础的应用程序,在反应本土化。多个选项卡使用相同的数据源(AsyncStorage)。如果我现在在一个选项卡中更新数据,然后打开另一个选项卡,就会显示旧的数据。我不知道,如何强制重新加载每一次的项目变得活跃。
{ this.setState({ selectedTab:'exploreTab‘});}}> { this.setState({ selectedTab:'favoriteTab‘});}> // Reload此 { this.setState({ selectedTab:'moreTab‘});}>
我已经尝试设置一个新的状态来触发更新,但是它似乎没有改变任何东西。
<TabBarIOS.Item
title="Favorites"
icon={{uri:'ic_favorite_border'}}
selected={this.state.selectedTab === 'favoriteTab'}
onPress={() => {
this.setState({
selectedTab: 'favoriteTab',
forceUpdate: Math.random()
});
}}>
<FavoritesView forceUpdate={this.state.forceUpdate}/>
</TabBarIOS.Item>发布于 2015-07-06 12:05:48
我也遇到了类似的问题,最终对我起作用的是在嵌入式视图上覆盖componentWillReceiveProps。只要视图在selectedTab中设置为TabBarIOS,就会调用它。
https://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops
发布于 2015-06-24 08:28:57
this在使用fat箭头表示法(this)时引用父组件。
尝试将一个ref添加到TabBar项中,并使用this.refs.refName.forceUpdate() (比使用随机值更新状态稍微好一些)。
https://stackoverflow.com/questions/31015045
复制相似问题