2014-09-30 4 views
2

나는 angularjs에 지침을 작성했습니다. 다음 코드를 사용하고 있습니다.

$('#TableID tr:has(td)') 

하지만 #TableID 즉 테이블 ID를 사용하고 싶지 않습니다. 이런 이유로 어떻게 위의 코드 대신 $ (this) 또는 this 또는 any를 사용합니까? 내 전체 지시자는 당신이 이벤트 대상을 얻고 JQuery와 함께 사용할 수있는 이벤트 개체를 얻을 수있는 $ 이벤트

directives.directive('niGroup', ['$timeout', function ($timeout) { 
     return { 
      restrict: 'A', 
      scope: false, 
      link: function (scope, element, attrs) { 
       function groupTable($rows, startIndex, total) { 
        if (total === 0) { 
         return; 
        } 
        var index, currentIndex = startIndex, count = 1, lst = []; 
        var tds = $rows.find('td:eq(' + currentIndex + ')'); 
        var ctrl = $(tds[0]); 
        //var $this = $(this); 
        //var ctrl = $this.text(); 
        lst.push($rows[0]); 
        for (index = 1; index <= tds.length; index++) { 
         var t1 = ctrl.text(); 
         var t2 = $(tds[index]).text(); 
         if (ctrl.text() == $(tds[index]).text()) { 
          count++; 
          $(tds[index]).css("display", "none");//hide(); //addClass('deleted'); 
          lst.push($rows[index]); 
         } 
         else { 
          if (count > 1) { 
           ctrl.attr('rowspan', count); 
           groupTable($(lst), startIndex + 1, total - 1); 
          } 
          count = 1; 
          lst = []; 
          ctrl = $(tds[index]); 
          lst.push($rows[index]); 
         } 
        } 
       } 
       scope.niGroups = scope.$eval(attrs.niGroup); 
       //get ListName 
       scope.listName = scope.niGroups.gridData; 
       scope.from = 0; 
       scope.groupLength = 1; 
       if (scope.niGroups.groupBy != undefined && scope.niGroups.groupBy.length > 1) { 
        scope.from = parseInt(scope.niGroups.groupBy.split(',')[0]); 
        scope.groupLength = parseInt(scope.niGroups.groupBy.split(',')[1]); 
       } 
       scope.$watchCollection(
        scope.listName, 
        function (newValue, oldValue) { 
         if (newValue !== oldValue) { 
          $timeout(function() { 
           groupTable($('tr:has(td)'), scope.from, scope.groupLength); 
          }, 0); 
         } 
        } 
       ); 
      } 
     }; 
    }]); 
+0

지시문 –

답변

0

사용 아래에 주어진다.

보십시오 here

+0

에 대한 코드를 게시합니다. 그러나 이벤트 나 $ 이벤트가 없습니다. –

관련 문제