我需要从这个 div 呈现内容:
<div class="col-sm-4">
<ul class="list-group">
<li class="list-group-item"><a href="#">File Reader</a></li>
<li class="list-group-item" ><a href="#">File Move</a></li>
<li class="list-group-item" ><a href="#">Data Base</a></li>
<li class="list-group-item"><a href="#">SAP R3</a></li>
<li class="list-group-item"><a href="#">FTP</a></li>
<li class="list-group-item"><a href="#">SOAP</a></li>
<li class="list-group-item"><a href="#">Rest</a></li>
<li class="list-group-item"><a href="#">Merge</a></li>
<li class="list-group-item"><a href="#">Filter</a></li>
<li class="list-group-item"><a href="#">Transform</a></li>
</ul>
</div>
进入拖放,我尝试了很多示例,但似乎没有任何效果。
这是我现在的代码:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { DragSource } from 'react-dnd';
import { ItemTypes } from './Constants';
import styles2 from './Styles.css'
import { render } from 'react-dom';
import {DragDropContext} from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';
const styles = {
fontFamily: 'sans-serif',
textAlign: 'center',
};
function collect(connect, monitor) {
return {
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
};
}
function _(id){
return document.getElementById(id);
}
var droppedIn = false;
function drag_start(event) {
_('app_status').innerHTML = "Dragging the "+event.target.getAttribute('id');
event.dataTransfer.dropEffect = "move";
event.dataTransfer.setData("text", event.target.getAttribute('id') );
}
function drag_enter(event) {
_('app_status').innerHTML = "You are dragging over the "+event.target.getAttribute('id');
}
function drag_leave(event) {
_('app_status').innerHTML = "You left the "+event.target.getAttribute('id');
}
function drag_drop(event) {
event.preventDefault(); /* Prevent undesirable default behavior while dropping */
var elem_id = event.dataTransfer.getData("text");
event.target.appendChild( _(elem_id) );
_('app_status').innerHTML = "Dropped "+elem_id+" into the "+event.target.getAttribute('id');
_(elem_id).removeAttribute("draggable");
_(elem_id).style.cursor = "default";
droppedIn = true;
}
function drag_end(event) {
if(droppedIn == false){
_('app_status').innerHTML = "You let the "+event.target.getAttribute('id')+" go.";
}
droppedIn = false;
}
function readDropZone(){
for(var i=0; i < _("drop_zone").children.length; i++){
alert(_("drop_zone").children[i].id+" is in the drop zone");
}
/* Run Ajax request to pass any data to your server */
}
const propTypes = {
text: PropTypes.string.isRequired,
// Injected by React DnD:
isDragging: PropTypes.bool.isRequired,
connectDragSource: PropTypes.func.isRequired
};
class BasicForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
render() {
return (
<div style={styles}>
<form onSubmit={this.handleSubmit}>
<div class="container">
<div class="row">
<div class="col-sm-4">
<ul class="list-group">
<li class="list-group-item"><a href="#">File Reader</a></li>
<li class="list-group-item" ><a href="#">File Move</a></li>
<li class="list-group-item" ><a href="#">Data Base</a></li>
<li class="list-group-item"><a href="#">SAP R3</a></li>
<li class="list-group-item"><a href="#">FTP</a></li>
<li class="list-group-item"><a href="#">SOAP</a></li>
<li class="list-group-item"><a href="#">Rest</a></li>
<li class="list-group-item"><a href="#">Merge</a></li>
<li class="list-group-item"><a href="#">Filter</a></li>
<li class="list-group-item"><a href="#">Transform</a></li>
</ul>
</div>
<h2 id="app_status">App status...</h2>
<h1>Drop Zone</h1>
<div id="drop_zone" onDragEnter="drag_enter(event)" onDrop="drag_drop(event)" onDragOver="return false" onDragLeave="drag_leave(event)" className={styles2.drop_zone} ></div>
</div>
</div>
<input type="submit" value="Submit" />
</form>
</div>
);
}
}export default DragDropContext(HTML5Backend)(BasicForm);
在我的控制台上,我收到这个错误:预期的onDragEnter
侦听器是一个函数,而不是一个string
类型的值。我在做什么错?PS:我是React的新手,我尝试了很多例子,所以代码有点大。