我的 JavaScript 代码如下
//我有一个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循环:
var results="";
for(var i=0;i<jsonRoles.roles.length;i++){
results += '<div class="dojoDndItem">' + jsonRoles.roles[i].roleName + '</div>';
}
//两个内容窗格如下,用于拖放两个块
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"
});
//设置边框容器的内容
innerBorderContainerAsAccordion.addChild(assignPermissionToUser1);
innerBorderContainerAsAccordion.addChild(assignPermissionToUser2);
我的问题是,如果我将一个元素从 DND 容器拖到另一个,它如何按 ID 或字母等排列/排序项目?
例如(下图)
两个容器的初始状态
将一些项目拖放到第二个 DND 容器后
如何强制对第二个 DND 容器的项目进行完全排序,如下所示:
任何人都可以帮忙吗?谢谢