2011-04-18 50 views
0

我想實現jQuery UI droppable and sortable example到我的PHP腳本的一個...jQuery的投擲的和排序與PHP IDS

的想法是用戶拖動和理清一切導出播放列表ID的排序順序,並處理它們後PHP ...我找到了this example,但我陷入了應該將playlist_id傳遞給jQuery的地步。到目前爲止,我一直在玩一些東西,但每次我recordsArray []包含「未定義」值或我搞砸了完整的輸出:)

請幫我這個簡單的一個:)

我的jQuery部分看起來是這樣的:

<script> 
    $(function() { 
     $("#playlist li").draggable({ 
      appendTo: "body", 
      helper: "clone" 
     }); 
     $("#export ol").droppable({ 
      activeClass: "ui-state-default", 
      hoverClass: "ui-state-hover", 
      accept: ":not(.ui-sortable-helper)", 
      drop: function(event, ui) { 
       $(this).find(".placeholder").remove(); 
       // GET ID SOMEHOW HERE! 
       $("<li id='???'></li>").text(ui.draggable.text()).appendTo(this); 
      } 
     }).sortable({ 
      items: "li:not(.placeholder)", 
      sort: function() { 
       $(this).removeClass("ui-state-default"); 
      }, 
      update: function() { 
       var order = $(this).sortable("serialize"); 
       $.post("<?php echo site_url('export/all/'); ?>", order); 
      } 
     }); 
    }); 
</script> 

和PHP部分:

echo "<div id=\"playlists\">"; 
    echo "<h3>PLAYLISTS</h3>"; 
    echo "<div id=\"playlist\">"; 
     echo "<div>"; 
      echo "<ul>"; 
       foreach ($all_playlists as $playlist) { 
        echo "<li id=\"recordsArray_&lt;".$playlist['playlist_id']."&gt;\">"; 
        echo "<font size=\"1\">".getFormattedDateAndTime($playlist['time'])."</font> ".br(); 
        echo "<font size=\"2\"><b>".$playlist['playlist_name']."</b></font>"; 
        echo "</li>"; 
       } 
      echo "</ul>"; 
     echo "</div>"; 
    echo "</div>"; 
echo "</div>"; 

echo "<div id=\"export\">"; 
    echo "<h3>EXPORT</h3>"; 
    echo "<div class=\"ui-widget-content\">"; 
     echo "<ol>"; 
      echo "<li class=\"placeholder\">DRAG HERE...</li>"; 
     echo "</ol>"; 
    echo "</div>"; 
echo "</div>"; 

在此先感謝!

回答

2

在drop事件你的UI對象是被丟棄的實際元素,所以爲了獲取ID

ui.draggable.attr('id') 
+0

哇! =)非常感謝! fala ti ko bratu ;-) – errata 2011-04-18 11:35:20

+0

@errata haha​​; nema frke buraz :): – 2011-04-18 11:36:50

0

我認爲你必須做兩件事情:

  • 代替$("#playlist li").draggable({必須$("#playlist ul").draggable({
  • 通過$啓動JavaScript代碼(文件)。就緒(函數(){})