首页 > react-native 在ListView的renderRow方法中获取当前state中的指定值,总是null

react-native 在ListView的renderRow方法中获取当前state中的指定值,总是null


 //片段1:
 <ListView
    dataSource={dataSource}
    renderRow={this._renderRow}
/>


//片段2:
class Demo extends Component {

    constructor(props) {
        super(props);
        this.state = {
            showId: 1
        };
    }

}

//片段3:
_renderRow (rowData: string, sectionID: number, rowID: number) {
       
    alert(this.state.showId)//报错

}
                       

片段一改改:

 //片段1:
 <ListView
    dataSource={dataSource}
    renderRow={this._renderRow.bind(this)}
/>
【热门文章】
【热门文章】