React Native renderRow错误:undefined不是对象(评估'e.id')

时间:2016-06-22 23:37:43

标签: listview react-native undefined react-native-listview

尝试在反应原生的ListView中renderRow。该列表由用户搜索的结果填充。有一个400 ms的去抖动以保持请求数量下降。问题是如果我在最后一个状态下发生renderRow时的setState更改应用程序将崩溃,并且未定义获取rowData.id。我试图通过严重的if语句来检测结果是否为'undefined'或null,并在渲染ListView之前检查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>
    );
  },

0 个答案:

没有答案