2017-10-24 9 views
0

내 테이블에 사용자 지정 열을 만들어야 동작을 수행 할 수 있고 행을 정의하는 개체에 따라 html 코드를 생성해야합니다.행 개체 데이터 및 html로 열 만들기

저는 각도에 익숙하지 않고 $ compile을 사용해야한다고 생각합니다. 그러나 어떻게해야할지 모르겠습니다.

열 정의 :

vm.dtColumns = [ 
    DTColumnBuilder.newColumn('name').withTitle("Name"), 
    DTColumnBuilder.newColumn(null).withTitle("Actions").notSortable() 
    .renderWith(function(data, type, full, meta) { 
    //imported code from a previous version where the code was generated from a ng-repeat directive 
    //project is the object, which can be found in the full parameter of the function 
    var html = '<button data-toggle="modal" data-target="#archiveProjectModal" type="button" class="btn btn-success col-sm-10 col-sm-offset-1" ng-if="project.active"><i class="fa fa-check">&nbsp;&nbsp;</i>Archiver</button>' 
    + '<a href="/project/{{project.id}}" type="button" class="btn btn-primary col-sm-10 col-sm-offset-1"><i class="fa fa-pencil">&nbsp;&nbsp;</i>Mettre à jour</a>' 
    + '<button data-toggle="modal" data-target="#deleteProjectModal" type="button" class="btn btn-danger col-xs-10 col-xs-offset-1"><i class="fa fa-trash">&nbsp;&nbsp;</i>Supprimer</button>' 
    //what should i return ? 
     return "?"; 
    }), 
]; 

누군가가 나를 도울 수 있습니까?

답변

0

당신은 반환 된 HTML 등등 ng-click처럼 호출되어야한다 지시어를 포함 할 경우에만 $compile 필요합니다 HTML 문자열

return html 

를 반환해야합니다. initComplete 콜백에서 수행 :

vm.dtOptions = DTOptionsBuilder.newOptions() 
    .withOption('initComplate', function() { 
    $compile(angular.element('#tableId'))($scope); 
    }) 
})