gpt4 book ai didi

javascript - Angularjs 从 url 获取 Json

转载 作者:行者123 更新时间:2023-11-27 22:32:15 25 4
gpt4 key购买 nike

第一次尝试获取json数据并使用AngularJS将其显示给我的应用程序,没有显示任何数据,这是我实现的代码

HTML

<div ng-app="myApp" ng-controller="customersCtrl"> 

<table>

<td>{{ x.id }}</td>
<td>{{ x.title }}</td>

</table>

</div>

</body>
</html>

脚本

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://example.com/api/get_page_index/")
.then(function (response) {$scope.names = response.data.pages;});
});
</script>

来自网址的 Json 内容

 {
"status": "ok",
"pages": [
{
"id": 2,
"type": "page",
"slug": "sample-page",
"url": "http:\/\/example.com\/",
"status": "publish",
"title": "example page",
"content": "",
"excerpt": "",
"date": false,
"modified": "2016-08-09 17:28:01",
"comments": [],
"attachments": [],
},

最佳答案

你可以做到这一点,

 <table>
<thead>
<tr>
<th ng-repeat="(header, value) in results[0]">
{{header}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in results">
<td ng-repeat="cell in row">
{{cell}}
</td>
</tr>
</tbody>
</table>

WORKING DEMO

关于javascript - Angularjs 从 url 获取 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39461523/

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