2016-03-28 35 views
0

當我運行這段代碼:陣營的ListView renderrow綁定

render: function() { 
    return (
     <ListView 
     dataSource = {this.state.dataSource} 
     renderrow = {this.renderBook.bind(this)} 
     key={"list" + i} 
     > 
     </ListView> 
    ); 
    } 
}); 

我得到這個消息:

無法讀取屬性未定義bind

我該怎麼解決呢?

回答

0

您不應該將(this)綁定到渲染函數中的函數。在構造函數中執行,或者您可以使用ES2016符號。

// constructor way 
constructor(props) { 
    super(props); 
    this.renderBook.bind(this) 
} 

// ES2016 way 
renderBook =() => {}