angular js 数据 table 将行数据传递给函数
angular js data table pass row data into fucntion
我在我的项目中使用 angular js 数据 table。目前我正在尝试将值传递给我的 onclick 函数。请检查我下面的代码
$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()
];
};
我正在尝试将我的 resultId 传递给我的 loadDataById 函数。但是没用。
我的函数如下
$scope.loadDataById = function (requestID) {
console.log(requestID)
};
我发现了一些关于我的问题的要点。当我使用数字时,打印控制台日志。但如果它的字符串,控制台日志没有打印。
例如:
full.resultId= 500;
console log print correctly as 500
full.resultId= '500asdx';
console log did not print.
为什么我不能使用字符串来执行此操作。我想你可以解决我的问题。谢谢
正如评论中所讨论的,唯一缺少的是 ng-click 函数中字符串的引号。解决方案:
ng-click="loadDataById(\'' + full.resultId + '\');"
或
ng-click="loadDataById(' + "'" + full.resultId + "'" + ');"
我会说选择第一个,因为它更干净
我在我的项目中使用 angular js 数据 table。目前我正在尝试将值传递给我的 onclick 函数。请检查我下面的代码
$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()
];
};
我正在尝试将我的 resultId 传递给我的 loadDataById 函数。但是没用。
我的函数如下
$scope.loadDataById = function (requestID) {
console.log(requestID)
};
我发现了一些关于我的问题的要点。当我使用数字时,打印控制台日志。但如果它的字符串,控制台日志没有打印。 例如:
full.resultId= 500;
console log print correctly as 500
full.resultId= '500asdx';
console log did not print.
为什么我不能使用字符串来执行此操作。我想你可以解决我的问题。谢谢
正如评论中所讨论的,唯一缺少的是 ng-click 函数中字符串的引号。解决方案:
ng-click="loadDataById(\'' + full.resultId + '\');"
或
ng-click="loadDataById(' + "'" + full.resultId + "'" + ');"
我会说选择第一个,因为它更干净