【问题标题】:Ng-table not calling get datang-table 没有调用获取数据
【发布时间】:2015-04-23 17:57:26
【问题描述】:

我已经用 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>

【问题讨论】:

  • 为什么你使用 $.ajax 而不是来自 angularjs 的 $http 服务
  • 我在另一个项目中使用它,效果很好
  • 我希望您使用 $http 服务而不是 $.ajax,而且您不应该将 jquery 与 angularjs 混合使用

标签: javascript jquery angularjs ngtable


【解决方案1】:

您的代码应该使用$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();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-25
  • 2017-01-20
  • 1970-01-01
  • 2017-09-19
相关资源
最近更新 更多