How to make two lists interchangeable, and when selection complete save dropped

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 04:01:11

问题


I am using jQuery and specifying two selectors together. Then I try to refer each variable in this code:

UL_HeadersToOmit - is the list to choose from

UL_dropedCols - is the list to be passed as reference to next function or "stage"

$('#next').click(
function () {

    var dropblUL = $('#UL_dropedCols li');
    alert(dropblUL.length);
});



$('#UL_dropedCols, #UL_HeadersToOmit')
    .sortable({
               connectWith: '#UL_HeadersToOmit, #UL_dropedCols'
             })
    .droppable({

            drop: function (event, ui) {
                     var curUL = $(this);
                    //.. now till here from what i could see in tests 
                    // drop is connected to the first  #dropedCols
                    // so if i wanted to specify same thing for second HeadersToOmit
                   // how will i do it ?

                  }
            });

I could see people at tutorials connecting

$(obj).draggable().droppable().sortable()

I guess this is ok if their all referring one object, but how will you refer two?

my goal is naturally : to save what user selected ...meaning whats left on #UL_dropedCols, at the end of the selection (keeping in mind user is playing between them-two, back and forth ) then clicking next.

update

http://jsfiddle.net/rhW7C/46/embedded/result/

http://jsfiddle.net/rhW7C/46/


回答1:


Solved: I was missing the receive event as seen below.

$('document').ready(function() {

    var results = [];

    $('#UL_dropedCols, #UL_HeadersToOmit').sortable({
        tolerance: 'pointer',
        connectWith: '#UL_HeadersToOmit, #UL_dropedCols',
        receive: function(event, ui) {
            var draged = ui.item.attr("id");
            results.push(draged);
        }
    });

    $('#next').click(function() {
        var RLength = results.length;
        for (var i = 0; i < RLength; i++) {
            alert(results[i]);
        }
    });

});


来源:https://stackoverflow.com/questions/14007417/how-to-make-two-lists-interchangeable-and-when-selection-complete-save-dropped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!