jQueryUI 操作可拖动克隆
编辑:我把这个问题删掉,然后把它放在上面
看看它是原始的,而不是被改变的新项目 http://jsfiddle.net/mikkelbreum/DBG5q
查看拖动的助手如何改变,但元素恢复一旦掉落即可返回。 http://jsfiddle.net/mikkelbreum/dpTC8
我有一个链接到可排序列表的可拖动列表
当我从可拖动到可排序时,我使用克隆的助手,因此原始对象仍保留在可拖动集合中。
每次我将克隆从可拖动列表拖动到可排序列表时,我想为新副本提供唯一的标题(操纵它的 h2 元素)。
我找不到解决新创建的元素的方法。
我尝试了两种方法:
一种是将辅助克隆定位在可拖动的开始事件处。 这里的问题是,尽管辅助克隆确实发生了更改,但在可排序列表中创建最终元素时,该更改不会复制到最终元素。在那里创建的新元素采用可拖动列表中原始元素的值,它是可拖动列表的克隆。
start: function(event, ui) {
ui.helper.find('h2').text('altered');
}
当我开始拖动时,我可以在克隆上更改更改,但是当将其放在可排序上时,h2 将重置为原始标题。
所以现在我尝试了第二种方法,我尝试在可排序的接收事件中更改新的原始元素:
receive: function(event, ui) {
ui.item.find('h2').text('altered');
}
这会改变我从中拖动元素的列表中原始元素的 h2 ,但新元素是在可排序内创建的仍然是旧的原始版本..
我如何定位/更改它?
EDIT: I Trimmed this question down, and put it on
See how it's the original and not the new item that gets altered
http://jsfiddle.net/mikkelbreum/DBG5q
See how the dragged helper gets altered, but the element reverts back once it's dropped.
http://jsfiddle.net/mikkelbreum/dpTC8
I've got a draggable list linked to a sortable list
When I drag from draggable to sortable I use a cloned helper, so the original is still left in draggable collection.
each time I drag a clone from the draggable list to the sortable list, I want to give the new copy a unique headline (manipulate it's h2 element).
I can't find a way to address the newly created element.
I've tried two approaches:
One is to target the helper clone at the start event in the draggable.
The problem here is, that although the helper clone does get changed, that change it is not copied over to the final element when it is created in the sortable list. The new element created there takes the value of the original in the draggable list of which it is a clone.
start: function(event, ui) {
ui.helper.find('h2').text('altered');
}
I can se the changes to altered on the clone when I start dragging, but when it is dropped on the sortable, the h2 is reset to the original heading.
So now I've tried a secondary approach where I instead try to alter the new original in the receive event of the sortable:
receive: function(event, ui) {
ui.item.find('h2').text('altered');
}
This alters the h2 of the original element over in the list I dragged the element from, but the new element that is created inside sortable is still as the old original..
How do I get to target/alter it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来问题是由于 jQueryUI BUG
另请参阅:jQuery UI Draggable/Sortable - 获取对新项目的引用
It seems that the problem is due to jQueryUI BUG
see also: jQuery UI Draggable/Sortable - Get reference to new item