Dojo Drag-Drop问题:对目标DND容器中的项进行排序 [英] Dojo Drag-Drop Issue: Sorting items in target DND container
本文介绍了Dojo Drag-Drop问题:对目标DND容器中的项进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的JavaScript代码如下
My JavaScript code is as below
//我有一个Json:
//I have a Json:
var jsonRoles = {"roles": [
{"roleId": "1", "roleName": "role1", "roleDesc": "This is role1"},
{"roleId": "2", "roleName": "role2", "roleDesc": "This is role2"},
{"roleId": "3", "roleName": "role3", "roleDesc": "This is role3"}
]
};
//要获取DND容器中列出的所有角色名称,我使用for循环:
//To get the all role name listed in DND container i used the for loop:
var results="";
for(var i=0;i<jsonRoles.roles.length;i++){
results += '<div class="dojoDndItem">' + jsonRoles.roles[i].roleName + '</div>';
}
//两个内容窗格如下,拖放两个块
//The two content panes are as below for two blocks for drag and drop
var assignPermissionToUser1 = new dijit.layout.ContentPane({
//splitter:true,
region: "left",
style: "background-color: white;width: 200px; height: 500px",
content:'<div>' + '<label>Roles</label>' + '</div>' + '<div dojoType="dojo.dnd.Source" id="rolelistNode" class="container">' +
'<div dojoType="dojo.dnd.Source" class="dojoDndItem movableContainer">' + '</div>' + results +
'</div>'
});
var assignPermissionToUser2 = new dijit.layout.ContentPane({
//splitter:true,
region: "right",
style: "background-color: white;width: 200px; height: 500px",
content:'<div>' + '<label>Users</label>' + '</div>' +'<div dojoType="dojo.dnd.Source" class="container">' +
'<div dojoType="dojo.dnd.Source" class="dojoDndItem movableContainer">' + '</div>' +
'</div>'
});
//边框容器
innerBorderContainerAsAccordion = new dijit.layout.BorderContainer({
id: "innerBorderContainerAsAccordion",
region: "center",
style: "background-color: white;width: 175px; height: 550px"
});
//设置边框容器的内容
//Set the contents of the border container
innerBorderContainerAsAccordion.addChild(assignPermissionToUser1);
innerBorderContainerAsAccordion.addChild(assignPermissionToUser2);
我的问题是如果我将元素从DND容器拖到另一个,怎么
例如(图像下方)
容器的初始状态
将一些项目拖放到第二个DND容器之后
如何强制对第二个DND容器的项目进行完全排序,如下所示: / strong>
How can I force fully sort the items of second DND container like this:
任何人都可以帮忙吗?谢谢
Can anyone help? Thank you
推荐答案
请尝试这段代码,这次它的javascript
Please try this code, and this time its javascript
function sortList(listId) {
// Get the ul object
var oUl = document.getElementById(listId);
/* Perform a Bubble Sort on the list items */
for (var i in oUl.childNodes) {
var x = oUl.childNodes[i];
for (var j in oUl.childNodes) {
var y = oUl.childNodes[j];
if ((x.innerText != 'undefined' || y.innerText != 'undefined') && x.innerText > y.innerText) {
// Skip if x is already the first list item
if (oUl.firstChild != x)
oUl.insertBefore(y, x);
}
}
}
}
/* Define innerText for Mozilla based browsers */
if ((typeof HTMLElement != 'undefined') && (HTMLElement.prototype.__defineGetter__ != 'undefined')) {
HTMLElement.prototype.__defineGetter__("innerText", function () {
var r = this.ownerDocument.createRange();
r.selectNodeContents(this);
return r.toString();
});
}
window.onload = function () {
sortList("ID_of_Your_ul_tag");
}
这篇关于Dojo Drag-Drop问题:对目标DND容器中的项进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文