我有一张这样的表:
<table ng-click="tableClick($event)" id="myTable"></table>
这样的功能:
$scope.tableClick = function($event) {
$('#myTable').find('tr').click( function($event) {
$scope.clickedRow = $(this).index();
});
$state.go('somePage', {
pageId : $scope.data[$scope.clickedRow].id
});
};
该函数基本上获取单击的行号,并使用该信息在数据中查找正确的id值。使用该id值,它会导航到另一个页面。
第一次点击时我调试代码并且它没有进入click函数,调试屏幕上$(this)的值是:
$get.Scope.$new.$$childScopeClass$$childHead: null$$childScopeClass: null$$childTail: null$$listenerCount: Object$$listeners: Object$$nextSibling: null$$prevSibling: $get.Scope.$new.$$childScopeClass$$watchers: null$id: "008"$parent: $get.Scope.$new.$$childScopeClasssummary: Array[7]tableClick: function ($event) {this: $get.Scope.$new.$$childScopeClass__proto__: $get.Scope.$new.$$childScopeClass]
我收到错误:
TypeError: Cannot read property '0' of undefined
at Scope.$scope.tableClick (http://localhost:9001/scripts/controllers/summary.js:129:53)
at Parser.functionCall (http://localhost:9001/bower_components/angular/angular.js:10847:21)
at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:9001/bower_components/angular/angular.js:19136:17)
at Scope.$get.Scope.$eval (http://localhost:9001/bower_components/angular/angular.js:12702:28)
at Scope.$get.Scope.$apply (http://localhost:9001/bower_components/angular/angular.js:12800:23)
at HTMLTableElement.<anonymous> (http://localhost:9001/bower_components/angular/angular.js:19141:23)
at HTMLTableElement.x.event.dispatch (http://localhost:9001/bower_components/iids/dist/iidx/components/jquery/jquery.min.js:5:14129)
at HTMLTableElement.x.event.add.v.handle (http://localhost:9001/bower_components/iids/dist/iidx/components/jquery/jquery.min.js:5:10873)
第一次点击后,实际返回该行及其索引号。
为什么没有$(这个)第一次加载表格行?我怎么加载它?