Javascript 角度js数据表将行数据传递到函数
我正在使用angular js数据表来创建我的项目。目前,我正在尝试将值传递给onclick函数。请检查我下面的代码Javascript 角度js数据表将行数据传递到函数,javascript,angularjs,datatable,Javascript,Angularjs,Datatable,我正在使用angular js数据表来创建我的项目。目前,我正在尝试将值传递给onclick函数。请检查我下面的代码 $scope.loadRequestApproval = function () { $scope.dtOptions = DTOptionsBuilder.newOptions() .withOption('ajax', { dataType: 'json', conten
$scope.loadRequestApproval = function () {
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
dataType: 'json',
contentType: "application/json; charset=utf-8",
url: appConfig.apiUrl + "/finalizedAllList?reqTraceId=" + $scope.requestApprovalId,
xhrFields: { withCredentials: true },
type: 'POST',
data: function (d) {
return JSON.stringify(d);
},
error: function (response) {
ajaxErrorHandler.handle(response);
}
})
.withDataProp('data')
.withOption('processing', true)
.withOption('serverSide', true)
.withOption('scrollY', '400px')
.withOption('scrollX', '100%')
.withOption('scrollCollapse', true)
.withOption('drawCallback', function (settings) {
});
$scope.dtOptions.withOption('fnRowCallback',
function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$compile(nRow, aData, iDisplayIndex, iDisplayIndexFull)($scope);
});
$scope.dtColumns = [
DTColumnBuilder.newColumn('treaceId.traceId').withTitle('Trace ID'),
DTColumnBuilder.newColumn('name').withTitle('Name'),
DTColumnBuilder.newColumn('matchRatio').withTitle('Match Strength %'),
DTColumnBuilder.newColumn('resultId').withTitle('Action').renderWith(function (data, type, full) {
full.resultId= '500asdx';
return '<div class="btn-group-xs">' +
' <button type="button" class="btn btn-flat btn-xs btn-success" ng-click="loadDataById(' + full.resultId+ ');">' +
' <i class="ion ion-eye"></i>' +
' </button>' +
'</div>';
}).withClass('text-center').notSortable()
];
};
关于我的问题,我发现了一些观点。当我使用数字时,会打印控制台日志。但如果是字符串,则不会打印控制台日志。
例:
为什么我不能用字符串来做这个。我想你可以解决我的问题。谢谢如评论中所述,唯一缺少的是ng click函数中字符串的倒逗号。解决方案:
ng click=“loadDataById(\'+full.resultId+'\');”
或
ng click=“loadDataById(+“+”+full.resultId++“+”;”
我要说的是,第一个更干净,因为它更干净Hi Kumara,我认为一个简单的答案是,在返回代码中,在ng click事件中有loadDataById函数,它将作为数字和
ng click=“loadDataById(500asdx)”
输出到DOM。这可能是字符串缺少倒逗号的原因。我如何修改我的代码,如果字符串比执行ng click=“loadDataById(\''+full.resultId++');“
或者ng click=“loadDataById('+'“+full.resultId+”);”更重要,你能帮我吗
我想说,买第一个吧,因为它很干净,而且很好用。非常感谢,我现在可以睡觉了:不用担心,乐意帮忙。我只想把这件事和问题的答案放在一起。如果你能把它标记为正确的,那会有帮助
$scope.loadDataById = function (requestID) {
console.log(requestID)
};
full.resultId= 500;
console log print correctly as 500
full.resultId= '500asdx';
console log did not print.