gpt4 book ai didi

javascript - 使用 AngularJS 打印 JSON 值

转载 作者:行者123 更新时间:2023-11-29 16:48:58 25 4
gpt4 key购买 nike

我正在尝试使用 AngularJS 从 JSON 端点打印一些数据。终点:- http://localhost:8081/api

JSON 结构:-

{
"1": {
"venture": "XYZ Informatics",
"member": [
{
"name": "abcd",
"email": "abcd@gmail.com"
}
],
"message": "This is good day",
"isclicked": false
},
"2": {
"venture": "BBC Informatics",
"member": [
{
"name": "xyz",
"email": "xyz@gmail.com"
}
],
"message": "This is bad day",
"isclicked": false
}
}

我想在行中显示 venture 的名称。我在行中的预期输出是:-

XYZ Informatics
BBC Informatics

我的代码是:-

    <!DOCTYPE html>
<html ng-app="MyApp">
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
</style>
</head>
<body>
<div ng-app="MyApp" ng-controller="displayController">
<table style="width:100%">
<tr ng-repeat="data in datas">
<td>{{ data.venture }}</td>
</tr>
</table>
</div>
<script>
angular.module('MyApp', [])
.controller('displayController', function($scope, $http) {
var url = "http://localhost:8081/api";
$http.get(url).success(function (response) {
$scope.datas = response;
});
}
</script>
</body>
</html>

但是没有显示值。可能,我想念每个 JSON 数组。

最佳答案

您的脚本存在语法错误。关闭 Controller 的括号。

  <script>
angular.module('MyApp', [])
.controller('displayController', function($scope, $http) {
//changed to your local api
var url = "http://localhost:8081/api";
$http.get(url).success(function(response) {
$scope.datas = response;
});
});//this is the place where you miss out the closing bracket
</script>

这是工作 plnkr .

关于javascript - 使用 AngularJS 打印 JSON 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38064961/

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