deanmcpherson / react-native-sortable-listview

Drag drop capable wrapper of ListView for React Native
MIT License
917 stars 235 forks source link

requested of keys a value that is not an object? #132

Closed labike closed 6 years ago

labike commented 6 years ago

image

import React, { Component } from 'react';
import {
    View,
    Text,
    StyleSheet
} from 'react-native';
import NavigationBar from '../../common/NavigatorBar';
import CustomTabPage from './CustomTabPage';
import LanguageViewPage, {FLAG_LANGUAGE} from '../../expand/data/LanguageViewPage';
import ArrayUtils from '../../utils/ArrayUtil';
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: []
        }
    }
    componentDidMount(){
        this.languageViewPage = new LanguageViewPage(FLAG_LANGUAGE.flag_key)
        this.loadDataTab()
    }
    loadDataTab(){
        this.languageViewPage.fetch()
            .then(result => {
                this.getCheckedItems(result)
            })
            .catch(error => {

            })
    }
    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
        })
        this.originCheckArray = ArrayUtils.clone(checkedArray)
    }
    render(){
        return (
            <View style={styles.container}>
                <NavigationBar 
                    title={'我的'}
                    style={{backgroundColor: '#2196f3'}}
                />
                <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>
        )
    }
}

class SortCell extends Component{
    render(){
        return <View>
            <Text>{this.props.data.name}</Text>    
        </View>
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff'
    },
    tips: {
        fontSize: 20
    }
})