ListView不会在状态更改时重新呈现

时间:2017-06-14 14:10:20

标签: javascript listview react-native

问题是这个。基于状态变量,我要么在ListView renderRow上渲染可重用的组件,要么返回null。

//renderRow 
if (this.state.openSections[sectionID] === false) {return null}

    return (<View style = {{flex :1, overflow : 'hidden'}}>
                <CalculatorItem item = {rowData}></CalculatorItem>
             </View>)

当按下某个部分时,openSections对象中的相应条目切换为true或false,表示应该呈现这些行,以便用户可见。

sectionPressed: function(sectionID) {
    ...
        //create a new openSections var and set the state
        this.setState((state, props) => { return {  openSections }});
    }

但是,不会呈现listview项目。

任何线索?

1 个答案:

答案 0 :(得分:0)

事情是ListView只有在其数据源发生变化时才会重新渲染。否则,它保持原样。因此,当您更改状态时,您可能还想更改dataSource属性中的值。

相关问题