標籤:
ListView相對於View的優點就在於可以不用一下子就把資料載入完,而是滑動著載入著資料,可以緩解資料載入,避免軟體卡死。
官方文檔:https://facebook.github.io/react-native/docs/listview.html#content
簡單使用:
constructor(props) { super(props); var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); this.state = { dataSource: ds.cloneWithRows([‘row 1‘, ‘row 2‘]) };}<ListView contentContainerStyle={{flexDirection: ‘row‘,flexWrap: ‘wrap‘, justifyContent:‘center‘}} dataSource={this.state.dataSource} initialListSize={14} renderRow={(rowData) =><Text>{rowData}</Text>}/> |
contentContainerStyle:設定list的樣式dataSource:資料來源initialListSize:官方文檔的解釋是指定在組件剛掛載的時候渲染多少行資料,但是在實際運用的時候,測試的根本不是這麼回事兒...(react版本0.23.0)renderRow:function();(rowData, sectionID, rowID, highlightRow) => renderable
從資料來源(dataSource)中接受一條資料,以及資料和資料所在section的ID。返回一個可渲染的組件來為這行資料進行渲染。
預設情況下參數中的資料就是放進資料來源中的資料本身,不過也可以提供一些轉換器。
ListView還有其它的一些設定,詳細可查看官方文檔。
ReactNative學習-ListView