jQuery Sortable - 如何获取当前拖动的元素属性

Kri*_*ris 7 jquery jquery-ui

我正在使用jqueryui可排序小部件.我需要获取当前拖动元素的数据属性.$(this).data('attribute_name')在这里不起作用.我也尝试过其他一些方法,但没有得到正确的结果.

HTML

<ul class="draggable-item" style="min-height:10px;">
   <li data-parent="31" data-id="81" class="ui-state-default">Label</li>
   <li data-parent="31" data-id="86" class="ui-state-default">Max Value</li>
   <li data-parent="31" data-id="83" class="ui-state-default">Unit</li>
   <li data-parent="31" data-id="84" class="ui-state-default">Warning Level High</li>
   <li data-parent="31" data-id="85" class="ui-state-default">Warning Level Low</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

JS

$(document).ready(function() {
  $(".draggable-item").sortable({
    start: function( event, ui ) { 
      //Here i need to get current dragged element's 'parent' attribue.
      //console.log(ui.item[0].attributes); - Here i got the entire attribute values in an array. But the order of the array is different in browsers.
    },
  }).disableSelection();
});
Run Code Online (Sandbox Code Playgroud)

Tom*_*now 6

试试$(ui.item).data('attribute_name');$(event.currentTarget).data('attribute_name');