reat-native-sortable-listview错误:请求的键是一个不是对象的值?

时间:2017-12-22 01:44:13

标签: react-native

enter image description here

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/

1 个答案:

答案 0 :(得分:1)

查看构造函数。你宣布州为:

this.state = {
  checkArray: [] // Change this to checkedArray
}