Jquery根据子元素的文本排序父div

时间:2017-11-05 16:50:18

标签: jquery html sorting

我想根据子元素的文本对父div进行排序。这是我的代码:

$('#ui-accordion-planner-itinWidget-itinsAccord-header-0, #planner-itinWidget-itinsAccord-0').wrapAll('<div id="ssiralama-1"></div>');
$('#ui-accordion-planner-itinWidget-itinsAccord-header-1, #planner-itinWidget-itinsAccord-1').wrapAll('<div id="ssiralama-2"></div>');
$('#ui-accordion-planner-itinWidget-itinsAccord-header-2, #planner-itinWidget-itinsAccord-2').wrapAll('<div id="ssiralama-3"></div>');
$('#ui-accordion-planner-itinWidget-itinsAccord-header-3, #planner-itinWidget-itinsAccord-3').wrapAll('<div id="ssiralama-4"></div>');


var value0 = $('#planner-itinWidget-itinsAccord-0 div .otp-itinTripSummary .sure').text();
var part0 = value0.split(" ");
if (part0[1]=="dakika") {
    value0 = part0[0];
} else {
    var part01 = value0.split(" ");
    var a0 = part01[0] * 60;
    value0 = a0 + parseInt(part01[2]);
}

var value1 = $('#planner-itinWidget-itinsAccord-0 div .otp-itinTripSummary .sure').text();
var part1 = value1.split(" ");
if (part1[1]=="dakika") {
    value1 = part1[0];
} else {
    var part02 = value1.split(" ");
    var a1 = part02[0] * 60;
    value1 = a1 + parseInt(part02[2]);
}

var value2 = $('#planner-itinWidget-itinsAccord-0 div .otp-itinTripSummary .sure').text();
var part2 = value2.split(" ");
if (part2[1]=="dakika") {
    value2 = part2[0];
} else {
    var part03 = value2.split(" ");
    var a2 = part03[0] * 60;
    value2 = a2 + parseInt(part03[2]);
}

var value3 = $('#planner-itinWidget-itinsAccord-0 div .otp-itinTripSummary .sure').text();
var part3 = value3.split(" ");
if (part3[1]=="dakika") {
    value3 = part3[0];
} else {
    var part04 = value3.split(" ");
    var a3 = part04[0] * 60;
    value3 = a3 + parseInt(part04[2]);
}


[value0, value1, value2, value3]
.map( (value, i) => [value, $('#ssiralama-' + i)] )
.sort( (a,b) => a[0].localeCompare(b[0]) )

.reduce( (a, b) => {
    a[1].after(b[1]);
return b;
});

我不确定,但我认为这些代码只会包含不安排div的div。 如何根据上面提到的重新排列我的父div?

0 个答案:

没有答案