1

反応ネイティブの ListView で renderRow を試みています。このリストは、ユーザー検索の結果から生成されます。リクエストの数を抑えるために、400 ミリ秒のデバウンスがあります。問題は、renderRow が最後の状態で発生しているときに setState を変更すると、rowData.id の未定義のフェッチでアプリがクラッシュすることです。結果が「未定義」またはnullであるかどうかを深刻なifステートメントでキャッチしようとしましたがthis.state.dataSource.getRowCount() === 0、ListViewをレンダリングする前にチェックしてこれを回避しようとしました。複数のセクションとヘッダーを持つ 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