[英]Uncaught TypeError: Cannot read property 'row' of undefined is not working in angular js
I want to read the values of row in a datatable
for that I Implemented something like this. 我想读连续的值
datatable
为我实现了这样的事情。
$('#entry-grid').on('click', '.check', function () {
var row = $(this).closest("tr");
var data = $scope.dtInstance.DataTable.row.data();
alert(data);
})
and below is my table 下面是我的桌子
<table id="entry-grid" datatable="" dtinstance="dtInstanceCallback" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"></table>
But while debugging I am getting error as 但是在调试时我得到了错误
Uncaught TypeError: Cannot read property 'row' of undefined
未捕获的TypeError:无法读取未定义的属性“行”
don't know why its giving the error 不知道为什么会给出错误
UPDATE UPDATE
Here is my updated anuglar code which I am trying to work it out but its not. 这是我更新的uguglar代码,我正在尝试解决,但不是。
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
进行驼峰式访问,因此等效的指令将被$scope.dtInstance
。
<table id="entry-grid" datatable="" dt-instance="dtInstanceCallback" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"></table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.