jquery сортируемое оповещение ID этого списка - PullRequest
1 голос
/ 05 мая 2011

Действительно нужна помощь

Я использую сортировку jquery.

И я хочу получить только идентификатор из перетаскиваемого элемента списка.

"Неall off them "

Вот пример http://jsfiddle.net/isimpledesign/85LdV/1/

, который возвращает массив, но мне нужно, чтобы он возвращал мне только идентификатор перетаскиваемого элемента, чтобы я мог передатьэто в php файл.

Может кто-нибудь, пожалуйста, помогите мне с этим ????

Ответы [ 3 ]

3 голосов
/ 05 мая 2011

Просто чтобы уточнить ответ Чада -

$(function() {
    $("#sortable").sortable({
        update: function(event, ui) {
            // i need to get the class text that is being dragged i.e
            var order = $(this).sortable("serialize");
            alert(order); 
            /*
             No need to bind any other events, ui.item is the dragged
             item in 'update' too and we only want to capture the id when the sort
             has changed presumably
            */
            alert(ui.item.attr('id'));
            /*
             No need for subscripting, ui.item is a jquery object so 
             we can just call attr() on it to get the ID
            */
        }
    });
});
0 голосов
/ 05 мая 2011

Используйте это:

$(function() {
    var lastMoved = null;
    $("#sortable li").mousedown(function(){
        lastMoved = this;
    });
    $("#sortable").sortable({
      update: function(event, ui) {
        alert($(lastMoved).attr("id"));
      }
    });
});

Это проверено и работает. Надеюсь это поможет. Приветствия.

0 голосов
/ 05 мая 2011

Используйте событие start:

$(function() {
   $("#sortable").sortable({
      update: function(event, ui) {
         // i need to get the class text that is being dragged i.e
        var order = $(this).sortable("serialize");
        alert(order);   
      },
      //Start event fires on the start of a sort
      //you can store the id from in here
      start: function(event, ui) {
         //here ui.item contains a jquery object that is the item being dragged
         alert(ui.item[0].id);
      }
   });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...