gpt4 book ai didi

javascript - 如何在jquery数据表行添加功能中传递html

转载 作者:行者123 更新时间:2023-12-03 09:01:17 25 4
gpt4 key购买 nike

以下是我从 Angular 在 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 数据表行中添加 html?

最佳答案

我必须编译 Angular 模板才能工作使用来自 Angular 的 $compile以下是我更改的代码:

  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);
}

关于javascript - 如何在jquery数据表行添加功能中传递html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32298810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com