AngularJS访问$http返回json数组
我有我删除的旧帖子,我在那里解决了它。 我还有其他问题: 这个数据数组来自PHP和$http(我使用console.log): 我无法使用ng repeat访问该数据:AngularJS访问$http返回json数组,angularjs,Angularjs,我有我删除的旧帖子,我在那里解决了它。 我还有其他问题: 这个数据数组来自PHP和$http(我使用console.log): 我无法使用ng repeat访问该数据: ibids.controller("auctions",function($http){ var req = { method: 'POST', url: 'includes/bids.php', headers: { 'Conte
ibids.controller("auctions",function($http){
var req = {
method: 'POST',
url: 'includes/bids.php',
headers: {
'Content-Type': 'json'
},
data: 'q=getAuctions'
}
$http(req).then(function(req){
console.log(req);
var auctionslist = req.data;
}, function(){
});
});
html:
{{man}}
{{x}
这里怎么了?我从php接收json数据,并在$http中完美地分配给数据数组。当我使用console.log(req)时,这就是您在图片中看到的,它接收json数组是完美的。
我不知道如何在该数据上使用ng repeat。您必须使用$scope并为该数据添加属性,然后在模板中使用它
ibids.controller("auctions",function($http, $scope){
var req = {
method: 'POST',
url: 'includes/bids.php',
headers: {
'Content-Type': 'json'
},
data: 'q=getAuctions'
}
$http(req).then(function(req){
console.log(req);
$scope.auctions = req.data;
}, function(){
});
});
和html格式
<body ng-controller="auctions">
<input type="text" value="test" ng-model="man">
{{man}}
<hr>
<div class="search" >
<input type="text">
<div class="res" ng-repeat="auction in auctions">
{{auction}}
</div>
</div>
{{man}}
{{拍卖}
好的,现在我看到了数据,但我只看到了第一个数组。你知道吗?例如,当我使用auction.name时,我会得到两个相同的名称,这是因为您的数据包含两个与屏幕截图中给出的名称相同的项目。我只是注意到抱歉!我不是焦点。非常感谢,现在一切都好了:)
<body ng-controller="auctions">
<input type="text" value="test" ng-model="man">
{{man}}
<hr>
<div class="search" >
<input type="text">
<div class="res" ng-repeat="auction in auctions">
{{auction}}
</div>
</div>