React Native:更改父元素中的元素后,子ListView将不会更新 [英] React Native: Child ListView will not update after element in parent is changed
问题描述
我似乎无法更新我的 ListView
.
我有一个带切换开关的父容器(< SegmentedControls/>
).当用户单击切换开关时,我希望子组件中的 ListView
使用更新的 reservationListSelectedOption
状态值进行更新.
I have a parent container with a toggle switch (<SegmentedControls />
). When the user clicks that toggle switch I'd like the ListView
in the child component to update using the updated reservationListSelectedOption
state value.
我想念什么?
此处的代码: https://gist.github.com/chapeljuice/69483ab0bde13346de024d4e4a9753f0
Code here: https://gist.github.com/chapeljuice/69483ab0bde13346de024d4e4a9753f0
推荐答案
实际上,我都找到了解决方案,这要归功于 thinhvo0108 和马特船尾帮助我到达那里.
Actually I found a solution, thanks to both thinhvo0108 and Matt Aft for helping me get there.
这是我修改后的 componentWillReceiveProps
函数,它与固定的dataSource结合使用,现在可以正确更新ListView:
Here is my revised componentWillReceiveProps
function, which combined with fixed dataSource is now updating the ListView correctly:
componentWillReceiveProps (nextProps) {
if ( nextProps.reservationListStatus === "Past Reservations" ) {
this.setState({
dataSource: ds.cloneWithRows(reservationData.previous)
})
} else {
this.setState({
dataSource: ds.cloneWithRows(reservationData.current)
})
}
console.log( 'nextProps.reservationListStatus: ' + nextProps.reservationListStatus );
}
我也使用工作代码更新了要点: https://gist.github.com/chapeljuice/69483ab0bde13346de024d4e4a9753f0
I updated my gist as well with the working code: https://gist.github.com/chapeljuice/69483ab0bde13346de024d4e4a9753f0
这篇关于React Native:更改父元素中的元素后,子ListView将不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!