【发布时间】:2014-08-23 14:11:48
【问题描述】:
我创建了一个拖放界面,最终将变成一个表单构建器。我创建了表单构建器http://jsfiddle.net/szASZ/1/ 的小提琴。当您将顶部项目之一拖到其下方的灰色拖放区时,一切似乎都正常工作。
但是,我遇到的问题是当您刷新页面/小提琴并尝试对放置区域内的项目进行排序时。如果您抓住第一个放置区顶部的“无线电输入”并将其移入或移出该放置区,则一切正常。
现在,尝试将最后一项“复选框输入”拖到其放置区域中,一切都应该正常工作。最后,刷新页面/小提琴并将最后一个“复选框输入”移动到另一个拖放区。占位符将显示,然后永远不会消失。我发现在拖放周期的这个实例中从未调用过“onDragEnd”事件,而是每隔一次调用一次。此事件通常会中继到表单构建器的顶层,在该构建器中它获取被拖动的项目并将其设置到新的数据数组中。
为了让事情变得更有趣,如果我将一个空对象添加到包含已删除项目的数组中(http://jsfiddle.net/szASZ/ - 第 30、34 行),一切都会按预期工作,因此看起来“放置区”项目数组未正确触发“onDragEnd”事件。
componentWillMount: function () {
var newInput = [
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Text Input" },
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Checkbox Input" },
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Radio Input" }
];
var newZones = [
[
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Radio Input" },
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Text Input" },
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Checkbox Input" }
,{}
],
[
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Text Input" },
{ "classes": "soft-half push-half--bottom brand-bg--gray-dark brand-color--white", "title": "Checkbox Input" }
,{}
]
];
this.setState({ inputs: newInput });
this.setState({ zones: newZones });
}
基本上,这是我遇到的主要问题,我不知道为什么其他所有项目都被排序、删除并且事件正确触发,但最后一个?谢谢!
【问题讨论】:
-
感谢您的详细描述和复制案例。
标签: javascript drag-and-drop reactjs