【问题标题】:ListView Will not re-rendered on state changeListView 不会在状态更改时重新渲染
【发布时间】:2017-11-16 18:00:15
【问题描述】:

问题是这样的。基于状态变量,我要么在 ListView 渲染行上渲染可重用组件,要么返回 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 项目不会被渲染。

有什么线索吗?

【问题讨论】:

  • 需要更多上下文。列表视图在哪里?
  • 你能在这里分享代码吗?

标签: javascript listview react-native


【解决方案1】:

问题是 ListView 仅在其数据源发生更改时才会重新呈现。否则,它将保持原样。因此,当您更改状态时,您可能还想更改 dataSource 属性中的值。

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2018-03-17
    相关资源
    最近更新 更多