I use sortable Here all js code
$(function() { a = [ ]; $("#head").disableSelection(); $('#variants').sortable({connectWith: '.sortContainer'}); var oldList, newList, item; $( ".sortContainer" ).sortable({ start: function(event, ui) { item = ui.item; newList = oldList = ui.item.parent().parent(); }, change: function(event, ui) { if(ui.sender) newList = ui.placeholder.parent().parent(); }, connectWith: '#variants,.sortContainer', receive: function(event, ui) { a.push(ui.item.attr("id")); alert(a+newList.attr('id')); }, remove: function(event, ui) { a.splice(a.indexOf('bar'), 1); alert(a); } }); $("#appendb").click(function() { random = Math.floor( Math.random() * 90 ) + 10; $('#variants').append("<div id='ans_"+random+"' class='variantions ui-state-error'>"+$( "#newans" ).val()+"</div>"); }); $("#appenq").click(function() { random = Math.floor( Math.random() * 90 ) + 10; $('.answers').append('<div class="answer" id="B'+random+'"> <div id="current" class="title">'+$("#newans").val()+'</div> <div class="sortContainer" id="'+random+'"></div>'); $( ".sortContainer" ).sortable({ start: function(event, ui) { item = ui.item; newList = oldList = ui.item.parent().parent(); }, stop: function(event, ui) { alert("Moved " + item.text() + " from " + oldList.attr('id') + " to " + newList.attr('id')); }, change: function(event, ui) { if(ui.sender) newList = ui.placeholder.parent().parent(); }, connectWith: '#variants,.sortContainer', receive: function(event, ui) { }, remove: function(event, ui) { a.splice(a.indexOf('bar'), 1); } }); }); }); How can I get data in the form of a block id (as an index) into which we move values (as values) in order to get an array of the following type:
arr = [{ idблока: 'idзначения' }, { idблока: 'idзначения' }]; And so that when adding a value to a block, this value was added to the array with the key (id) of the block to which the value was moved, and when the value was removed from the block, it was deleted accordingly.
Working example here: https://jsfiddle.net/morrowinds/kb18ncgm/29/
arr = { idблока: 'idзначения', idблока: 'idзначения' };you do not have an array, but an object; to get an array, you need to make the following construction:arr = [{ idблока: 'idзначения' }, { idблока: 'idзначения' }];- MasterAlex