は、私のコメントをもとに、簡単な例である:
https://jsfiddle.net/Twisty/3x64npfw/
JavaScriptの
$(function() {
var preChange, postChange;
function equalArr(a, b) {
console.log("Compare", a, b);
var eq = 0;
$.each(a, function(k, v) {
if(a[k] != b[k]){
eq++;
}
});
return (eq ? false : true);
}
$("#sortable").sortable({
start: function(event, ui) {
preChange = $(this).sortable("toArray");
},
stop: function(event, ui) {
postChange = $(this).sortable("toArray");
$(".results").html("After change, the list is the " + (equalArr(preChange, postChange) ? "same." : "different."));
}
});
});
これは、リストの各項目にid
属性が必要であることを示します。それらを使用しない場合は、リストを反復し、各項目を読み込み、配列を吐き出す関数を作成したいと思うでしょう。
function listToArray(target){
var items = target.children();
var myArray = [];
items.each(function(){
myArray.push($(this).text());
});
if(myArray.length == 0){
return false;
}
return myArray;
}
これを参照してください:https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript –
参照してください。http://api.jqueryui.com/sortable/#method- toArrayはアイテムIDの配列を返します。文字列が必要な場合は、http://api.jqueryui.com/sortable/#method-serializeを使用して、2つを比較することができます。 – Twisty