ReactNative學習-ListView

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.