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

问题描述 投票:0回答:1

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/

react-native
1个回答
1
投票

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

this.state = {
  checkArray: [] // Change this to checkedArray
}
© www.soinside.com 2019 - 2024. All rights reserved.