jquery - Jquery UI Sortable 获取父子位置
问题描述
小提琴:http : //jsfiddle.net/johndavemanuel/htLx358f/17/
$(document).ready(function(){
// Sort the parents
$(".sortable").sortable({
containment: "parent",
items: "> div",
handle: ".move",
tolerance: "pointer",
cursor: "move",
opacity: 0.7,
revert: 300,
delay: 150,
dropOnEmpty: true,
placeholder: "movable-placeholder",
start: function(e, ui) {
ui.placeholder.height(ui.helper.outerHeight());
}
});
// Sort the children
$(".group-items").sortable({
containment: "document",
items: "> div",
connectWith: '.group-items'
});
})
我有 3 个 DIV 作为父级,它是可排序的,其中有其他 DIV 作为子级,
我工作得很好我可以对父母和孩子进行排序,我的问题是我怎样才能像这样获得所有人的“序列化”位置
家长 2
孩子 1
孩子 4
家长 1
孩子 2
孩子 5
家长 3
孩子 3
孩子 6
我将用它来保存他们的位置,所以当用户回来时它会像这样
任何帮助将不胜感激。
解决方案
function createArrayFromSortableList() {
var sortables = $(".group-caption");
sortables.each(function() {
var fields = [];
$(this).find('div.group-item.field').each(function() {
fields.push({
id: $(this).attr("data-id"),
sectionID: $(this).closest(".group-caption").find('.section-title').attr("data-id"),
fieldName: $.trim($(this).find(".field-name").text().replace(/[\t\n]+/g, ' ')),
fieldPosition: $(this).closest(".group-items").attr("data-column")
});
});
sections.push({
id: $(this).find('.section-title').attr("id"),
sectionName: $(this).find('.section-title').text(),
zfields: fields
});
});
console.log(sections);
console.log(JSON.stringify(sections));
}
输出:
推荐阅读
- django - 在 Django 视图中重新组合模型中的数据
- javascript - 在用作边框源的 SVG 中悬停时启动 CSS 动画
- java - 使用 JFrame 形式 (Java) 中的缓冲写入器打印 ArrayList
- python - 熊猫分组错误重复轴但没有重复值
- javascript - 仅当所有字段不为空时才启用提交按钮 - 类型 > 文件 & 选择 & 输入
- google-chrome - AR - Google Scene Viewer - FCA 是如何做到这一点的?
- ios - 如何减少iOS导航栏自定义视图的左右间隙
- database - 通过 Episerver API/数据库查询获取 Episerver 属性
- r - 使用 traceplot 函数从链收敛图中删除非典型内部线
- python - 如何使用“pytest_terminal_summary”钩子避免额外的换行符