2016-08-11 47 views
2

我對listview的重新渲染機制感到困惑。listview在setState({ds})後消失

Page 1已經呈現了兩個項目的列表視圖,然後我點擊'添加'按鈕,導航到另一個頁面,並添加一個項目到頁面1的數據源,然後導航回來。

我期望看到的是帶有三個項目的頁面1,但實際上是Page 2,listview消失了。但是如果我用鼠標/手指觸摸它,listView會再出現三個項目。 我測試它在我的iPhone和模擬器

1的源代碼:

class Market extends Component { 
    constructor(props) { 
    super(props) 
    this.state = { 
    dataSource: new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }), 
    } 
} 

componentDidMount() { 
    this.refreshListView(this.props.data) 
} 

componentWillReceiveProps(nextProps) { 
    this.refreshListView(nextProps.data) 
} 

refreshListView() { 
    this.setState({ 
    dataSource: this.state.dataSource.cloneWithRows(data) 
    }) 
} 

render() { 
    return (
    <ListView 
     dataSource={this.state.dataSource} 
     renderRow={this._renderRow} 
     refreshControl={ 
     <RefreshControl/> 
     } 
    /> 
) 
} 

const mapStateToProps = createSelector(
    selectData(), 
    (data) => ({ 
    data, 
    }) 
) 

export default connect(mapStateToProps)(Market) 
+0

林 - 您使用的反應本地'0.31.0'?我認爲這可能是一個錯誤,因爲我的應用程序在更新前工作正常 – David

+0

@David我使用0.30.0,我沒有在0.31.0上測試它,也許我應該在版本<0.30.0上測試它 – hulajesus

回答