2012-02-04 2 views
0

jQuery를 dataTables Plugin과 함께 사용합니다. dataTables는 행을 열고 닫을 수있는 기능을 제공합니다. 추가 정보 행을 일반 행 아래 열 수 있음을 의미합니다.jQuery HTMLElement 포장/풀기

$(document).ready(function() { 
    var oTable; 

    // 'open' an information row when a row is clicked on 
    $('#example tbody tr').click(function() { 
     if (oTable.fnIsOpen(this)) { 
      oTable.fnClose(this); 
     } else { 
      oTable.fnOpen(this, "Temporary row opened", "info_row"); 
     } 
    }); 

    oTable = $('#example').dataTable(); 
}); 

가 지금은 전체 행에 있지 클릭 처리기를 추가 할 수 있지만, 행의 요소 :

$("#openCompliantsTable .icon-comment").click(… 

그러나 http://datatables.net/api에서 내가 잘 작동 다음 예제있어

물론 thistr 요소를 참조하지 않고 일부 자식 요소를 참조합니다. 코드를 변경하려는 시도는 을 $(this).parent().parent().get()으로 바꾸는 것이었지만 작동하지 않았습니다.

는 그런 사실 this 모두가 나를 놀라게 [object HTMLElement] 객체 경우에도 $(this).get()과 동일하지 않는 것 같습니다 것을 발견했다.

이 제안을 받으려면 어떤 제안을 원하십니까?

편집 : 내 HTML 테이블은 다음과 같다 : 매개 변수없이

<table id="openCompliantsTable" class="table table-striped table-bordered table-condensed"> 
    <thead> 
     <tr> 
     <th>Reklamationsnummer</th> 
     <th>Reklapositionsnummer</th> 
     ... 
     <th>Status</th> 
     <th>Aktion</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td>1</td> 
     <td>1</td> 
     ... 
     <td>offen</td> 
     <td><i class="icon-ok"></i><i class="icon-trash"></i><i class="icon-flag"></i><i class="icon-comment"></i></td> 
     </tr> 
     ... 
    </tbody> 
    </table> 
+0

정말 $ (this) .parent(). parent()'가 TR 요소를 찾았습니까? –

+0

예, 일부 CSS 클래스를 추가 할 수 있습니다. – thorink

답변

1

.get()는 일치하는 모든 요소의 모든 DOM 요소와 배열을 반환합니다. 일치하는 요소가 하나만있는 경우에도 하나의 항목이있는 배열이 생성됩니다.

색인을 사용하면 .get()이 인 을 검색합니다.

$(this).parent().parent().get(0) 
+0

고마워요, 그게 다야! – thorink

2

$(this).parent().parent().get(0) 

함수가 될 수

$(this).parent().parent().get() 

로 교체 :

$('#openCompliantsTable .icon-comment').click(function() { 
    var tr = $(this).parent().parent().get(0); 
    if (oTable.fnIsOpen(tr)) { 
     oTable.fnClose(tr); 
    } else { 
     oTable.fnOpen(tr, "Temporary row opened", "info_row"); 
    } 
}); 

당신은 사용해야합니다

this example도 참조하십시오.

0

이하 :

$(this).parents('tr')[0]; 

이것은 'TR', 중첩 중요하지 않습니다 첫 번째 부모를 소요하고 당신은 당신이 단계로 얼마나 많은 수준에 대해 걱정하지 않아도됩니다. 중첩 된 테이블이 있으면 조심하십시오.

관련 문제