1

试图在反应原生的 ListView 中渲染行。该列表是根据用户搜索的结果填充的。有 400 毫秒的去抖动以减少请求的数量。问题是如果我在最后一个状态上发生 renderRow 时 setState 更改应用程序将因未定义的获取 rowData.id 而崩溃。我试图通过一系列 if 语句来捕捉结果是否为“未定义”或 null,同时this.state.dataSource.getRowCount() === 0在渲染 ListView 之前进行检查以尝试避免这种情况。它是一个包含多个部分和标题的列表视图。

 renderRow: function(
    rowData: Object,
    sectionID: number | string,
    rowID: number | string,
    highlightRowFunc: (sectionID: ?number | string, rowID: ?number | string) => void,      
  ) {
    if(rowData) {
      switch(sectionID) {
        case GLOBAL.PATHWAYTITLE:
        if(rowData){
          var content = <PMSearchPathwayCell
            refs="cell"
            key={rowData.pathway_id}
            onSelect={() => this.selectPathway(rowData) }
            onSelectMore={() => this.onSelectMore(rowData) }
            onHighlight={() => highlightRowFunc(sectionID, rowID) }
            onUnhighlight={() => highlightRowFunc(null, null) }
            pathway={rowData}
            /> 
        }
            break;
        case GLOBAL.PICMONICTITLE:
          if (rowData == null) {
            console.log(rowData.id);
          }
          if(rowData) {
          var content = <PMSearchCardCell
            refs="cell"
            key={rowData.id}
            onSelect={() => this.selectCard(rowData) }
            onSelectMore={() => this.onSelectMore(rowData) }
            onHighlight={() => highlightRowFunc(sectionID, rowID) }
            onUnhighlight={() => highlightRowFunc(null, null) }
            card={rowData}
            />
          }
            break;
            //Default added. Since we provide the array of pathwaytitle and picmonictitle this isn't a scenario that we 
            //should ever encounter. 
        default:
        console.log("SectionID for rowRender not set!");
        var content = <Text>Not Available</Text>
            break;
      }
    } 

    return (
      <View>
      {content}
      </View>
    );
  },
4

0 回答 0