有没有办法在拖动可排序项目时刷新可排序项?
我有几个部分,每个部分都有项目。这些项目是可排序的对象,我可以将它们从一个部分拖放到另一个部分。我们的一些客户有大量的部分和大量的项目,这使得浏览器崩溃。当我最初设计它时,我还很陌生,所以效率并没有真正在我的考虑范围内,但现在我正在重新审视脚本,我遇到了一个问题。
为了解决这个问题,我在部分列表上使用ajax使用延迟加载,其中只有当单击“打开部分”按钮时才从服务器获取项目。我们在低效系统中拥有的一个功能是,用户可以将拖动的项目放在关闭的部分上 500 毫秒,然后它将打开该部分。
这是生成的 HTML:
<ul class="sections ui-sortable" style="display: block;">
<li id="s_3" class="ui-droppable">
<input type="hidden" value="3" name="section_id">
<span class="sectionName">Section 1</span>
<ul class="items ui-sortable" style="">
<!-- Items can go here -->
</ul>
</li>
<li id="s_11" class="ui-droppable">
<input type="hidden" value="11" name="section_id">
<span class="sectionName">Section 2</span>
<ul class="items ui-sortable" style="display: block;">
<li id="i_32">
<input type="hidden" value="32" name="item_id">
<span class="itemName">Item 1</span>
</li>
</ul>
</li>
</ul>
我遇到的问题是排序函数使用新填充的项目列表得到了所有的错误。
这就是我的制作方法,以便可以通过将鼠标悬停在列表上来打开列表:
//sElement is the .sections ul
function initItemDroppable( sElement ) {
sElement.find('> li').droppable({
accept: '.items > li',
over: function( event, ui ) {
var section = $(this);
var section_id = section.find('input[name="section_id"]').val();
// only start the counter if the container isn't already visible
if( !$(section).find('.items').is(':visible') ) {
$( document ).oneTime( '500ms', 'expandCategoryTimer', function(){
//get the items and populated the list
getItems( section_id );
//according to jquery, refreshes the positions of all the sortable objects
$('.sections, .items').sortable('refreshPositions');
} );
}
},
out: function( event, ui ) {
$( document ).stopTime( 'expandCategoryTimer' );
}
});
}
我认为我需要的只是可排序内容上的“refreshPosition”方法,但它并没有完全解决问题。我可以将一个项目放在列表的末尾,但我不能将其放在其他项目之间,除非我将其放下并再次将其重新拾起。有什么想法吗?
I have sections and each section has items. These items are sortable objects which I can drag and drop from one section to another. A few of our clients have a TON of sections with a TON of items which makes the browser fall to it's knees. I was pretty green when I initially designed it so efficiency wasn't really on my radar but now I'm revisiting the script and I've bumped into a problem.
To solve the problem I use lazy loading using ajax on my section lists where the items are only fetched from the server when they click on the "open section" button. A feature we have in the inefficient system is that a user can hold a dragged item over a close sections for 500ms and it will open the section.
This is the generated HTML:
<ul class="sections ui-sortable" style="display: block;">
<li id="s_3" class="ui-droppable">
<input type="hidden" value="3" name="section_id">
<span class="sectionName">Section 1</span>
<ul class="items ui-sortable" style="">
<!-- Items can go here -->
</ul>
</li>
<li id="s_11" class="ui-droppable">
<input type="hidden" value="11" name="section_id">
<span class="sectionName">Section 2</span>
<ul class="items ui-sortable" style="display: block;">
<li id="i_32">
<input type="hidden" value="32" name="item_id">
<span class="itemName">Item 1</span>
</li>
</ul>
</li>
</ul>
The problem I have is that the sorting function gets all screwie with a newly populated item list.
This is how I make it so lists can be opened by hovering over them:
//sElement is the .sections ul
function initItemDroppable( sElement ) {
sElement.find('> li').droppable({
accept: '.items > li',
over: function( event, ui ) {
var section = $(this);
var section_id = section.find('input[name="section_id"]').val();
// only start the counter if the container isn't already visible
if( !$(section).find('.items').is(':visible') ) {
$( document ).oneTime( '500ms', 'expandCategoryTimer', function(){
//get the items and populated the list
getItems( section_id );
//according to jquery, refreshes the positions of all the sortable objects
$('.sections, .items').sortable('refreshPositions');
} );
}
},
out: function( event, ui ) {
$( document ).stopTime( 'expandCategoryTimer' );
}
});
}
I thought all I needed was the "refreshPosition" method on the sortable stuff but it's not quite doing the trick. I'm allowed to drop an item at the END of the list but I can't drop it inbetween other ones unless I drop it and pick it back up again. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你知道我讨厌什么,当你在某件事上被困几个小时时,寻求帮助,然后稍后找到答案。
事实证明,我实际上并不是在寻找
refreshPositions
,而只是简单的refresh
。当我获取项目并将它们移动到屏幕上时,我会刷新它们的位置,然后调用刷新以使新添加的项目能够被当前拖动识别。我本来打算删除我的问题,但后来想这也许可以帮助我以外的人;)
You know what I hate, when you're stuck on something for hours, ask for help, and then find the answer moments later.
Turns out I wasn't actually looking for
refreshPositions
but just plain ol'refresh
. When I get items and move them on the screen I refresh their position and then call refresh to have newly added items to be recognized by the current drag.I was going to delete my question but then thought maybe this could help someone aside from me ;)