javascript - jquery/javascript 在 ng-view 中不起作用
问题描述
我正在尝试通过角度路径提供帮助来实现 SPA,因为我正在使用 ng-view 来注入视图。在一个页面中,我有一个 jquery 数据表,我需要在其中获取使用 jquery 选择的行的索引。但这并没有在 ng-view 中发生。我也尝试使用指令,但没有运气。有人可以帮我吗
主页.html
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
</table>
获取选定的行
控制器.Js:
app.controller("HomeController", function ($scope, $http,$window) {
$('#example').DataTable({
"ajax": {
"url": "test.json",
"dataSrc": ""
},
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
],
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[1, 'asc']]
});
$scope.$broadcast('dataloaded');
$scope.Customers = $("example").DataTable().data;
console.log("Result: ", $scope.Customers.length);
$scope.GetDetails = function () {
var table = $("example").DataTable();
var rowid = table.row(this).index();
alert(rowid);
};
$scope.GetRowID = function () {
$('#example tbody').on('click', 'tr', function () {
console.log("inside");
debugger;
var table = $("#example").DataTable();
alert('Row index: ' + table.row(this).index());
});
};
$scope.init();
解决方案
推荐阅读
- asp.net - MongoDb GridFS 不适用于 Azure CosmosDb
- python - AttributeError:“RunCmd”对象没有属性“p”,Python 子进程
- c# - 如何使用聚合对结果进行分组?
- excel - VBA如何写入/修改函数中的单元格
- git - 有没有办法使用 git 统一管理依赖关系?
- javascript - 新用户注册后如何显示“新帐户已创建”消息
- python - 按照键对键映射转换 Python 字典键
- unit-testing - Liferay 服务的单元测试
- ios - IOS Swift 嵌套垂直 StackView
- amazon-web-services - 如何使用 cloudformation 模板中的用户数据将文件从 s3 存储桶复制到 ec2 实例