首页 > 解决方案 > 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();

标签: javascriptjqueryangularjs

解决方案


推荐阅读