2011-09-06 52 views
4

我已經在我的網站中實現了JQuery拖放插件。它工作得很好,但是,我試圖訪問正在排序的div,但發現很難選擇它。JQuery拖放:訪問Sortable()Divs

所以,我試圖選擇每個列中的每個「dragbox」。這通常是簡單的工作,但出於某種原因,我無法訪問它,並且無法在FireBug中看到它。

有沒有人有任何想法如何使用循環訪問cols中的「dragbox」項?謝謝大家!

編輯:

我也用find()方法,並沒有工作

<div class="column" id="col1"> 

     <div class="dragbox" id="item1" > 
      control goes here 
     </div> 
     <div class="dragbox" id="item1" > 
      <!-- control goes here --> 
     </div> 
    </div> 


    <div class="column" id="col2">    
     <div class="dragbox" id="item3" > 
      <!-- control goes here --> 
     </div> 
    </div> 

我使用下面的JQuery:

$('.column').sortable({ 
     connectWith: '.column', 
     handle: '.widget-header-holder', 
     cursor: 'move', 
     placeholder: 'placeholder', 
     forcePlaceholderSize: true, 
     opacity: 0.4, 
     stop: function(event, ui) { 
      $(ui.item).find('.widget-header-holder').click(); 
      var sortorder = ''; 
      $('.column').each(function() { 
       var itemorder = $(this).sortable('toArray'); 
       var columnId = $(this).attr('id'); 
       sortorder += columnId + '=' + itemorder.toString() + '&'; 
      }); 
      /*alert('SortOrder: ' + sortorder);*/ 
      console.log(sortorder);     
     } 
    }); 
+0

也許你想.find? $('。column')。find('。dragbox')。each ...,在你的情況下你可以做'$('。column')。each(function(){$(this).find(' '.dragbox')。each(...));' – Matt

+0

是的,我已經使用查找,它不工作 – Funky

+0

是找到或toArray應該工作,不知道爲什麼它不適合你。也許設置一個jsfiddle腳本並檢查。 – Matt

回答

5

我演示代碼發揮各地有些,它確實對我來說確實很好。

http://jsfiddle.net/U24TS/1/

您可以看到的,只要和你有IDS指定者確實工作。

+0

如果我將所有物品拖到單側後,我不能拖放到另一側。爲什麼? –