非常教程

React native参考手册

其他 | Miscellaneous

ListViewDataSource

提供有效的数据处理和对ListView组件的访问。A的ListViewDataSource功能是从输入blob提取数据,并比较元素(为了方便,默认实现)。输入blob可以像字符串数组一样简单,或者具有嵌套在段对象内的行的对象。

要更新数据源中的数据,请使用cloneWithRows(或者cloneWithRowsAndSections如果您关心部分)。数据源中的数据是不可变的,所以您不能直接修改它。克隆方法吸收新数据并计算每行的差异,以便ListView知道是否重新呈现它。

在这个例子中,一个组件接收数据块,由其处理_onDataArrived,将新数据连接到旧数据并更新数据源。我们concat用来创建一个新的数组 - this._data例如,使用变异this._data.push(newRowData)将是一个错误。_rowHasChanged了解行数据的形状并知道如何有效地比较它。

getInitialState: function() {
  var ds = new ListView.DataSource({rowHasChanged: this._rowHasChanged});
  return {ds};
},
_onDataArrived(newData) {
  this._data = this._data.concat(newData);
  this.setState({
    ds: this.state.ds.cloneWithRows(this._data)
  });
}

方法

constructor(params)

您可以hasChanged为节标题和行提供自定义提取和功能。如果不存在,数据将使用defaultGetRowDatadefaultGetSectionHeaderData函数提取。

默认提取器需要以下格式之一的数据:

 { sectionID_1: { rowID_1: <rowData1>, ... }, ... }

或者

 { sectionID_1: [ <rowData1>, <rowData2>, ... ], ... }

或者

 [ [ <rowData1>, <rowData2>, ... ], ... ]

构造函数接受一个params参数,该参数可以包含以下任何一个参数:

  • getRowData(dataBlob,sectionID,rowID);
  • getSectionHeaderData(dataBlob, sectionID);
  • rowHasChanged(prevRowData, nextRowData);
  • sectionHeaderHasChanged(prevSectionData, nextSectionData);

cloneWithRows(dataBlob, rowIdentities)

ListViewDataSource用指定的dataBlob和克隆这个rowIdentities。这dataBlob只是一个任意的数据。在构建过程中,获取有趣信息的提取器已定义(或使用默认值)。

rowIdentities是行的标识符的二维数组。即。['a1','a2','b1','b2','b3',...]。如果未提供,则假定段数据的键是行标识。

注意:此功能不会克隆此数据源中的数据。它只是将构造中定义的函数传递给指定数据的新数据源。如果你想维护现有的数据,你必须分别合并旧的和新的数据,然后把它作为参数传递给这个函数dataBlob

cloneWithRowsAndSections(dataBlob, sectionIdentities, rowIdentities)

这与函数执行相同的功能,cloneWithRows但在这里您还指定了自己的sectionIdentities功能。如果你不关心你应该安全使用的部分cloneWithRows

sectionIdentities是部分的标识符数组。即。's1','s2',....标识符应该与您希望包含的数据的键或数组索引相对应。如果未提供,则假定dataBlob的密钥是节标识。

注意:这会返回一个新的对象!

const dataSource = ds.cloneWithRowsAndSections({
  addresses: ['row 1', 'row 2'],
  phone_numbers: ['data 1', 'data 2'],
}, ['phone_numbers']);

getRowCount()

返回数据源中的总行数。

如果您指定rowIdentities或sectionIdentities,getRowCount则将返回已过滤数据源中的行数。

getRowAndSectionCount()

返回数据源中的总行数(请参阅getRowCount计算方法)以及数据中的部分数量。

如果您正在指定rowIdentities或sectionIdentities,getRowAndSectionCount则会返回已过滤数据源中的行数和部分数量。

rowShouldUpdate(sectionIndex, rowIndex)

如果行被弄脏并需要重新渲染,则返回

getRowData(sectionIndex, rowIndex)

获取呈现该行所需的数据。

getRowIDForFlatIndex(index)

获取在索引处提供的rowID,如果dataSource数组已平展,或者null超出范围索引。

getSectionIDForFlatIndex(index)

如果dataSource数组已平展,则获取索引处的sectionID;如果超出范围索引,则获取null。

getSectionLengths()

返回包含每个节中的行数的数组

sectionHeaderShouldUpdate(sectionIndex)

如果节标题变脏并需要重新渲染,则返回

getSectionHeaderData(sectionIndex)

获取呈现节标题所需的数据

其他 | Miscellaneous相关

React native

React Native 是一个 JavaScript 的框架,用来撰写实时的、可原生呈现 iOS 和 Android 的应用。

主页 https://facebook.github.io/react-native/
源码 https://github.com/facebook/react-native
发布版本 0.49

React native目录

1.开始 | Getting Started
2.指南 | Guides
3.APIs
4.组件:ActivityIndicator | Components: ActivityIndicator
5.组件:按钮 | Components: Button
6.组件:CheckBox | Components: CheckBox
7.组件:DatePickerIOS | Components: DatePickerIOS
8.组件:DrawerLayoutAndroid | Components: DrawerLayoutAndroid
9.组件:FlatList | Components: FlatList
10.组件:图像 | Components: Image
11.组件:KeyboardAvoidingView | Components: KeyboardAvoidingView
12.Components: ListView
13.Components: MaskedViewIOS
14.Components: Modal
15.Components: NavigatorIOS
16.Components: Picker
17.Components: PickerIOS
18.Components: ProgressBarAndroid
19.Components: ProgressViewIOS
20.Components: RefreshControl
21.Components: ScrollView
22.Components: SectionList
23.Components: SegmentedControlIOS
24.Components: Slider
25.Components: SnapshotViewIOS
26.Components: StatusBar
27.Components: Switch
28.Components: TabBarIOS
29.Components: TabBarIOS.Item
30.Components: Text
31.Components: TextInput
32.Components: ToolbarAndroid
33.Components: TouchableHighlight
34.Components: TouchableNativeFeedback
35.Components: TouchableOpacity
36.Components: TouchableWithoutFeedback
37.Components: View
38.Components: ViewPagerAndroid
39.Components: VirtualizedList
40.Components: WebView
41.创建 | Contributing
42.指南(Android) | Guides (Android)
43.指南(IOS) | Guides (iOS)
44.其他 | Miscellaneous