/** * @author oldj * @blog https://oldj.net */ 'use strict' import React from 'react' import classnames from 'classnames' import Sortable from 'sortablejs' import listToArray from 'wheel-js/src/common/list-to-array' import './group.less' export default class Group extends React.Component { constructor (props) { super(props) this.state = { list: [] } this.current_hosts = null } makeItem (item) { let attrs = { 'data-id': item.id || '' } return (
{item.title}
) } makeList () { let items = this.state.list .filter(item => item.where !== 'group') .map(item => this.makeItem(item)) return (
{items}
) } currentList () { return (
) } getCurrentListFromDOM () { let nodes = this.refs.group_current.getElementsByClassName('hosts-item') nodes = listToArray(nodes) console.log(nodes) } componentWillMount () { this.setState({ list: this.props.list }) } componentDidMount () { Sortable.create(this.refs.group_valid, { group: 'sorting' , sort: false }) Sortable.create(this.refs.group_current, { group: 'sorting' , sort: true , onSort: evt => { this.getCurrentListFromDOM() } }) } render () { return (
{this.makeList()}
{this.currentList()}
) } }