gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'row' of undefined is not working in angular js

转载 作者:行者123 更新时间:2023-12-03 00:23:34 24 4
gpt4 key购买 nike

我想读取数据表中的行值,因为我实现了类似的东西。

$('#entry-grid').on('click', '.check', function () {
var row = $(this).closest("tr");
var data = $scope.dtInstance.DataTable.row.data();
alert(data);
})

下面是我的 table

<table id="entry-grid" datatable="" dtinstance="dtInstanceCallback" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"></table>

但是在调试时我收到错误

Uncaught TypeError: Cannot read property 'row' of undefined

不知道为什么会出现错误

更新

这是我更新的 anuglar 代码,我正在尝试解决它,但事实并非如此。

var app = angular.module('MyApp', ['datatables']);
app.controller('homeCtrl', ['$scope', '$http', 'DTOptionsBuilder', 'DTColumnBuilder',
function ($scope, $http, DTOptionsBuilder, DTColumnBuilder) {
$scope.dtColumns = [
DTColumnBuilder.newColumn(null, '').renderWith(function(data, type, full) {
return '<input type="checkbox" class="check" data-object-id="'+full.objectid+'">'
}),
DTColumnBuilder.newColumn("OBJECTID", "ID"),
DTColumnBuilder.newColumn("SERVICE_CODE", "Service Code"),
DTColumnBuilder.newColumn("COND1", "Condition 1"),
DTColumnBuilder.newColumn("COND2", "Condition 2"),
DTColumnBuilder.newColumn("COND3", "Condition 3"),
DTColumnBuilder.newColumn("SERVICE_TYPE", "Service type"),
DTColumnBuilder.newColumn("REMARK", "Remark"),
DTColumnBuilder.newColumn("DESCRIPTION", "Description")
]
$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
url: "/home/getdata",
type: "POST"
})
.withPaginationType('full_numbers')
.withDisplayLength(10);

$scope.dtInstance = {};
$scope.dtIntanceCallback = function (instance) {
$scope.dtInstance = instance;
}
$scope.dtRebind = function () {
$scope.dtInstance.DataTable.draw()
}

$('#entry-grid').on('click', '.check', function () {
var row = $(this).closest("tr");
var data = $scope.dtInstance.DataTable.row().data(); // here is the error of row undefined
})
}])

最佳答案

如果我没记错的话,正确使用的指令应该是 dt-instance 而不是 dtinstance,因为您将其作为 $scope.dtInstance 访问 是驼峰式的,所以等效的指令是 kebab 式的。

<table id="entry-grid" datatable="" dt-instance="dtInstanceCallback" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"></table>

关于javascript - 未捕获的类型错误 : Cannot read property 'row' of undefined is not working in angular js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54200045/

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