【发布时间】:2017-04-19 17:19:33
【问题描述】:
在我的 Angular 应用程序中,我正在从 javascript 动态创建表格。
$("#tableName").html("<table id='dtData' name='dtData' dt-options='dtOptions' dt-columns='dtColumns' class='table table-striped table-bordered'></table>");
这是我生成列的方式
var header = data[0], dtColumns = [];
//create columns based on first row in dataset
for (var key in header)
{
// console.log(key);
if(key == "sendEmail")
{
dtColumns.push(DTColumnBuilder.newColumn(key).withTitle("Send Email").renderWith(actionsHtml));
}
else
{
dtColumns.push(DTColumnBuilder.newColumn(key).withTitle(key));
}
}
这是actionsHtml函数
function actionsHtml(data, type, full, meta) {
return '<input type="checkbox" name="sendEmail" value="' + data+'">';
}
我在这里完成这张表
$scope.dtColumns = dtColumns;
//create options
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('data', data)
.withOption('dataSrc', '');
//initialize the dataTable
angular.element('#dtData').attr('datatable', '');
$compile(angular.element('#dtData'))($scope);
它创建表,然后是复选框类型的列,但它不会将值绑定到复选框。这是表
列的控制台值
但问题是.. chechbox 列绑定不起作用.. 我从 html 或 javascript 中选中/取消选中它,它不会对表/原始列表进行任何更改。
我们将不胜感激。
【问题讨论】:
标签: javascript angularjs checkbox dynamic-columns