问题
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