gpt4 book ai didi

javascript - AngularJS dataTable,$http get 不起作用

转载 作者:行者123 更新时间:2023-11-28 04:15:42 27 4
gpt4 key购买 nike

当我从 $http.get 获取 ng-repeat 对象时,AngularJS 中的数据表不起作用。 (第一个表有效,第二个表无效)https://codepen.io/bafu2203/pen/VzBVmy

JS:

var app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
app.controller('validationCtrl',function($scope, $http, $timeout){
$scope.getapi = function(){
$http({
method: 'GET',
url: 'https://www.w3schools.com/angular/customers_mysql.php',
})
.then(function successCallback(data) {
$scope.test = data.data.records;
console.log($scope.test);
$timeout($scope.getapi, 1000);
}, function errorCallback(response) {
console.log(response);
console.log('error');
});

};
$scope.getapi();


$scope.data={ "records":[ {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"}, {"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"}, {"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"}, {"Name":"Around the Horn","City":"London","Country":"UK"}, {"Name":"B's Beverages","City":"London","Country":"UK"}, {"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"}, {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"}, {"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"}, {"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"}, {"Name":"Bon app'","City":"Marseille","Country":"France"}, {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"}, {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"}, {"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"}, {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"}, {"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"} ] }



$scope.dataTableOpt = {
//custom datatable options
// or load data through ajax call also
"aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
"aoSearchCols": [
null
],
};
});

最佳答案

使 Api 调用一次次。然后将其添加到对象或数组中。然后过滤该对象/数组。现在看来,每次按下任何过滤功能时,您都会调用 Api。使其可以在 api 函数外部访问。

//Outside function
$scope.testData = {};

//Inside
$scope.testdata = data.data.records;

关于javascript - AngularJS dataTable,$http get 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45878526/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com