1
私のリストビューに行が追加されているとき、私は奇妙な動作をしています。私の論理がどこに間違っているのか分かりません。私は、反応ネイティブタブビューを使用してタブを持っています。私はReact-Native listviewを更新するには?
を表示されているもの、これはあるオブジェクトを追加する前にタブ2に、私は、オブジェクトを追加し、戻った後、タブ4に表示されている「お気に入り」の配列にオブジェクトを追加していタブ4に、これは私が見ていますものです
とコード
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
constructor(props) {
super(props)
this.state = {
favoriteDB: props.favorites,
renderPlaceholder: true,
dataSource: ds.cloneWithRows([])
}
}
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
this.setState({
dataSource: ds.cloneWithRows(this.state.favoriteDB),
renderPlaceholder: false
})
})
}
componentWillReceiveProps(prevProps) {
const {favorites} = this.props
if (JSON.stringify(favorites) != JSON.stringify(prevProps.favorites)) {
this._updateFavorites()
}
}
_updateFavorites() {
const {favorites} = this.props
this.setState({
favoriteDB: favorites,
dataSource: ds.cloneWithRows(favorites)
})
}
render() {
const {dataSource} = this.state
const {visibleHeight, visibleWidth} = this.props
if (this.state.renderPlaceholder)
return <Placeholder/>
return (
<Container theme={theme}>
<View style={{ flex:1, height: visibleHeight - 100, width: visibleWidth }}>
<Row>
<Col>
<List>
<ListView
style={{ height: visibleHeight - 100, width: visibleWidth }}
enableEmptySections={TRUE}
automaticallyAdjustContentInsets={FALSE}
initialListSize={100}
pageSize={100}
dataSource={dataSource}
renderRow={rowData => this._renderRow(rowData)}/>
</List>
</Col>
</Row>
</View>
</Container>
)
}
を参照してくださいあなた 'はconsole.log(お気に入り)'場合、あなたは項目の配列全体または追加したものを取得していますか? –
全体の配列 – texas697
@MattAft「ベイカー、マルレンヌJ」の上の疑わしい空間、それは何ですか? –