gpt4 book ai didi

javascript - Ng-table 不调用获取数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:16 24 4
gpt4 key购买 nike

我已经通过 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 - Ng-table 不调用获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29830985/

24 4 0