TabSortPage.js
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet
} from 'react-native';
import SortableListView from 'react-native-sortable-listview';
export default class TabSortPage extends Component{
constructor(props){
super(props)
this.dataArray = []
this.sortResultArray = []
this.originCheckArray = []
this.state = {
checkArray: []
}
}
getCheckedItems(result){
this.dataArray = result
let checkedArray = []
for(let i = 0, len = result.length; i < len; i++){
let data = result[i]
if(data.checked){
checkedArray.push(data)
}
}
this.setState({
checkedArray: checkedArray
})
}
render(){
return (
<View style={styles.container}>
<SortableListView
style={{flex: 1}}
data={this.state.checkedArray}
**order={Object.keys(this.state.checkedArray)}**
onRowMoved={e => {
this.state.checkedArray.splice(e.to, 0, this.state.checkedArray.splice(e.from, 1)[0])
this.forceUpdate()
}}
renderRow={row => <SortCell data={row} />}
/>
</View>
)
}
}
60中的代码行,得到错误:
order={Object.keys(this.state.checkedArray)}
keys
是值,不是对象吗?但Object.keys
返回object
,
如何解决错误?并返回一个值,而不是对象?谢谢! react-native-sortable-listview地址:https://github.com/deanmcpherson/react-native-sortable-listview/
答案 0 :(得分:1)
查看构造函数。你宣布州为:
this.state = {
checkArray: [] // Change this to checkedArray
}