我检查了这些:
Jquery draggable/droppable and sortable combined
jQuery UI: sortable and draggable + sortable and droppable
JQuery Draggable + Droppable + Sortable
所以,答案不是这些。
理论
问题
你试过什么?
$(function() {
$( ".fetchedfromdb li" ).draggable({
appendTo: "body",
helper: "clone",
drag: function(){
$(".sortintodb ol").droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function(event, ui) {
$( this ).find( ".placeholder" ).remove();
$( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );
}
}).sortable({
sort: function() {
$( this ).removeClass( "ui-state-default" );
}
});
}
});
});
我的 COdeIgniter 部分:
<?php
echo form_open('/data/process');
echo form_label('yep') . form_textarea('remarks');
foreach($dataFetched as $data => $field) {
echo "<h2>$data</h2> \n <ul class='fetchedfromdb'>";
foreach($field as $f):
$fieldFetch = $data.'_1_1';
echo '<li>'.$f->$fieldFetch.'</li>';
echo "<br />";
endforeach;
echo '</ul>';
echo '<div style="background-color: #c3c3c3; height:100px">';
echo "<ol class=\"sortintodb\" id=\"$data\">";
echo '<li class="placeholder">Drop here</li>
</ol>
</div><hr />';
}
echo form_submit('submit','Submit');
echo form_close();
?>
通过 CSS 我确保每个输出直到父 foreach 结束都在同一部分
关于如何实现的任何想法?
任何帮助,非常感谢。谢谢 :)
我们正在查看的“视觉”表示...
最佳答案
这是工作演示。 Jsfiddle Demo
HTML
<ul class='fetchedfromdb' id="da1"> //parent element
<li id="1">Data1</li>
<br />
<li id="2">Data2</li>
<br />
<li id="3">Data3</li>
<br />
<div style="background-color: #c3c3c3; height:100px">
<ol class="sortintodb" id="e201">
<li class="placeholder" id="9">Drop here</li>
</ol>
</div>
</ul>//ends
<hr />
<h2>e202</h2>
<ul class='fetchedfromdb'>
<li id="5">Data1</li>
<br />
<li id="6">Data2</li>
<br />
<li id="7">Data4</li>
<br />
<div style="background-color: #c3c3c3; height:100px">
<ol class="sortintodb" id="e202">
<li class="placeholder" id="8">Drop here</li>
</ol>
</div>
</ul>
<hr />
脚本
$(".fetchedfromdb li").draggable({
containment: 'parent',
helper: "clone",
connectToSortable: '.sortable',
});
$(".sortintodb").droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function(event, ui) {
var self = $(this);
//if you don't want same "data" in placeholder more than once
self.find(".sortintodb").remove();
var dropId = ui.draggable.attr('id');
if (self.find("[id=" + dropId + "]").length) return;
$("<li></li>", {
"text": ui.draggable.text(),
"id": dropId
}).appendTo(this);
},
});
$('.sortintodb').sortable({
placeholder: "ui-state-highlight",
});
关于javascript - 多个可拖放和可排序的 jQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19304068/