2015-01-15 4 views
0

불행히도 jsfiddle에서이 작업을 수행하지 못했지만 어쩌면 뭔가 (간추린 내용) (http://jsfiddle.net/bJpyU/46/)가 있습니다. 동적으로 생성 된 블록이 있고 배치 된 순서를 저장해야합니다. 역동적 인 방식으로 설정되었으므로 인덱스를 가져올 수 없습니다 (항상 0이고 블록 시작은 항상 끌어온 위치에 관계없이 첫 번째 인덱스로 표시됩니다). toArray 및 serialize가 비어있는 것으로 표시됩니다. 나는 심지어 제 n 자녀를 세어 보았습니다. 순서를 얻는 방법 어떤 아이디어?동적 jquery와 정렬 가능한 블록의 색인/위치?

HTML

<div class="tab-pane active col-lg-12" id="portlet_tab_Graphs"> 
    <div class="row padLR sortable_portlets" id="sortable_portlet_Graphs"> 

     <div class="col-lg-4 sortable sortable_portlet_Graphs_column ui-sortable" id="102"> 
      <div class="portlet box yellow"> 
       <div class="portlet-title">Monthly License Revenue</div> 
      </div> 
      <div class="portlet-body clearfix pad"> 
       <div id="h1_sortable_portlet_Graphs_102"></div> 
       <div id="sortable_portlet_Graphs_102"> 
        <div class="col-lg-12 nPad"> 
         <div class="btn-group chartToggle inline">Graph Data</div> 
        </div> 
       </div> 
      </div> 
     </div>   
     <div class="col-lg-4 sortable sortable_portlet_Graphs_column ui-sortable" id="103"> 
      <div class="portlet box blue"> 
       <div class="portlet-title">Yearly License Revenue</div> 
      </div> 
      <div class="portlet-body clearfix pad"> 
       <div id="h1_sortable_portlet_Graphs_102"></div> 
       <div id="sortable_portlet_Graphs_102"> 
        <div class="col-lg-12 nPad"> 
         <div class="btn-group chartToggle inline">Graph Data</div> 
        </div> 
       </div> 
      </div> 
     </div> 

    </div> 
</div> 

JQUERY

var sortdiv = "Graphs" 
var blockClasses = "col-lg-4"; 

    $(".sortable_portlet_" + sortdiv[2] + "_column").sortable({ 
     connectWith: ".sortable_portlet_" + sortdiv[2] + "_column", 
     handle: ".portlet-title", 
     //placeholder: "dragColumn", 
     forceHelperSize: true, 
     forcePlaceholderSize: true, 

     start: function (e, ui) { 
      ui.placeholder.height(ui.helper.outerHeight()); 
      ui.placeholder.width(ui.helper.outerWidth()); 

      // get original block size 
      blockClasses = ui.item.parent().attr('class'); 
     }, 
     stop: function (e, ui) { 
      var parent = ui.item.parent(); 

      blockWidth = blockClasses.split(" "); 

      parent.attr('class', function (i, c) { 
       return c.replace(/(^|\s)col-lg-\S+/g, blockWidth[0]); 
      }); 

      //console.log(ui.position) 
      SavePortletDrop(sortdiv[2]); 
     } 
    }); 
+0

초기 관찰 : 다음이'sortdiv = 'Graphs''하지만'sortdiv [2]'. sortdiv가 배열인가, 아니면'[2]'가 에러입니까? – evanbikes

답변

1

나는 오류가 당신이 분류하고 각 항목에 sortable를 연결에서 실제로 생각합니다. 컨테이너 div에 첨부해야합니다.

그래서, 그것은 작동 것처럼, 당신은 실제로 당신이 원하는 생각처럼 내가 그것을 가지고 0

이 작동하려면 인덱스에 항상 1 항목 목록, 한 무리의 주위에 이동 한 모습에도 불구하고 #sortable_portlet_Graphssortable을 첨부하십시오. 이로 인해 ui.item.index()stop 함수에서 예상되는 숫자를 반환합니다.

http://jsfiddle.net/bJpyU/47/

+0

생명의 은인. 정말 고맙습니다. – triplethreat77