2015-08-30 30 views
0

以下是即時從角如何通過HTML jQuery的數據錶行添加功能

reviewManger.GetUnapprovedReviews().then(function (data) { 
    if (data != null) { 
     var result = Reviews.Common.MakeValidJSON(data); 
     if (result != null) { 
      $scope.reviews = result; 
      var table = $("#editable"); 

      var tp = table.DataTable(); 
      for (var i = 0; i < $scope.reviews.length; i++) { 
       tp.row.add([ 
        $scope.reviews[i].ID, 
        $scope.reviews[i].AddedOn, 
        $scope.reviews[i].Company.Name, 
        $scope.reviews[i].User.Name, 
        $scope.reviews[i].Description, 
        $sce.trustAsHtml("<span ng-click='EnableDisable(" + $scope.reviews[i].ID + ")>Change</span>") 
       ]).draw(); 
      } 
     } 
    } 
}, function (error) { 
}); 

的問題將在jQuery的數據表列方式是我在所有行的最後一欄沒有看到所呈現的HTML jQuery數據表中,所有其他列都填充在所有行中。

如何在jQuery數據表格行中添加html?

+0

你是如何在模板結合的trustedHTML? – sjt003

回答

1

我不得不編譯角模板爲了工作 使用$從角 編譯以下是我改變了代碼:

if (result != null) { 
        $scope.reviews = result; 
        var table: any = $("#editable"); 
        //table.DataTable(); 
        var tp = table.DataTable(); 

        for (var i = 0; i < $scope.reviews.length; i++) { 
         var id = $scope.reviews[i].ID; 
         var checked = $scope.reviews[i].Enabled == "1" ? true : false; 
         tp.row.add(
          [ 
           $scope.reviews[i].ID, 
           $scope.reviews[i].AddedOn, 
           $scope.reviews[i].Company.Name, 
           $scope.reviews[i].User.Name, 
           $scope.reviews[i].Description, 
           "<div class='switch'><div class='onoffswitch'><input ng-checked='" + checked+"' class='onoffswitch-checkbox' id= 'stat" + id + "' type= 'checkbox'><label class='onoffswitch-label' for='stat" + id + "'><span class='onoffswitch-inner'></span><span class='onoffswitch-switch'></span></label></div></div>" 
           //"<div class='switch'><div class='onoffswitch'><input checked='' class='onoffswitch- checkbox' id= 'stat" + id + "' type= 'checkbox'><label class='onoffswitch- label' for='stat" + id + "'><span class='onoffswitch- inner'></span><span class='onoffswitch-switch'></span></label></div></div>" 
           //"<button ng-click='EnableDisable(" + $scope.reviews[i].ID + ")'>Change</button>" 

          ] 
          ); 
        } 

        tp.draw(); 

        $compile(table)($scope); 
       } 
0

你必須綁定信任的html與<div ng-bind-html="tp.row[x]"></div>或類似的東西來獲得html替代品。我看不到你的標記,所以它取決於。可能有利於您發佈標記。

相關問題