React Native

React-Native的FlatList和SectionLis

2017-09-04  本文已影响197人  踏云小子

FlatList的简述

简单的栗子

<FlatList
  data={
    [{key: 'a'}, {key: 'b'}, {key: 'c'}, {key: 'd'}]
  }
  renderItem={
    ({item}) => <Text>{item.key}</Text>
  }
/>
image.png

SectionList的简述

简单的栗子

<SectionList
    renderItem={
      ({item}) => <Text style={{color: 'black', padding: 10}}>{item.key}</Text>
    }
    renderSectionHeader={
      ({section}) => <Text style={{color: 'green', padding: 10}}>{section.title}</Text>
    }
    sections={
      [ // 不同section渲染相同类型的子组件
        {data: [{key: 'Will'}, {key: 'Javion'}, {key: 'Cater'}], title: 'title1', key:'title1'},
        {data: [{key: 'Will'}, {key: 'Javion'}, {key: 'Cater'}], title: 'title2', key:'title2'},
        {data: [{key: 'Will'}, {key: 'Javion'}, {key: 'Cater'}], title: 'title3', key:'title3'},
      ]
    }
/>
image.png
上一篇下一篇

猜你喜欢

热点阅读