我已经通过 ajax 调用实现了 ng-table,但从未从 getdata 调用该函数,从不调用 onBuscarTable 函数,我查看了调试器控制台来检查它并且没有调用它:

我在做什么错?

这是js:

    $scope.onBuscarTable = function ($defer, params) {
    $.ajax({
        type: 'GET',
        url: '/Home/GetEfficiencyDetails',
        cache: false,
        contentType: 'application/json; charset=utf-8',
        //data: JSON.stringify({ title: "fghfdhgfdgfd" }),
        success: function (data) {
            $scope.items = data;
            $defer.resolve(data);
        }
    });
};

//$scope.getEffiencyDetails();
$scope.tableBuscar = new ngTableParams({
    page: 1, // show first page
    count: $scope.items.length, // hides pager
    sorting: {
        name: 'asc' // initial sorting
    }
}, {
    counts: [], // hides page sizes
    getData: $scope.onBuscarTable

});

$scope.tableBuscar.reload();

这是html:
                            <table ng-table="tableBuscar" show-filter="true" class="table table-striped table-bordered table-condensed table-hover">

                            <tbody>
                                <tr>
                                    <th colspan="5">Battery Life</th>
                                    <th colspan="4">SBC</th>
                                    <th colspan="3">ZBC</th>
                                    <th>Overall</th>
                                </tr>
                                <tr>
                                    <th>Pool #</th>
                                    <th>True Cap.</th>
                                    <th>Util.</th>
                                    <th>Load Sharing</th>

                                </tr>
                                <tr ng-repeat="item in items">
                                    <td>{{item.PoolName}}</td>
                                    <td>{{item.AvgTrueCapacity}}</td>
                                    <td>{{item.AvgEnergyUsageDaily}}</td>
                                </tr>

                            </tbody>
                        </table>

最佳答案

你的代码应该使用 $http 而不是 $.ajax

$scope.items = [];
$scope.onBuscarTable = function($defer, params) {
    $http.get('/Home/GetEfficiencyDetails').success(function(data) {
        $scope.items = data;
        $defer.resolve(data);
    });
};

//$scope.getEffiencyDetails();
$scope.tableBuscar = new ngTableParams({
    page: 1, // show first page
    count: $scope.items.length, // hides pager
    sorting: {
        name: 'asc' // initial sorting
    }
}, {
    counts: [], // hides page sizes
    getData: $scope.onBuscarTable

});

$scope.tableBuscar.reload();

关于javascript - 吴表不调用获取数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29830985/

10-12 12:57
查看更多