gpt4 book ai didi

javascript - 将 json 数据中的文本显示到我的 html 文本框中

转载 作者:行者123 更新时间:2023-11-28 00:20:31 24 4
gpt4 key购买 nike

这是我的文本框的 html 文本:

<div class="row">
<div class="col-md-2">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<div class="alert alert-info alert-dismissable">
<textarea class="form-control3" rows="3" placeholder="Clue 1"></textarea>
<textarea class="form-control4" rows="3" placeholder="Answer"></textarea>
<input type="text" class="form-control1" placeholder="10">
<input type="text" class="form-control2" placeholder="Rejected">
<div>
<img src="images/up.png" width="13px" ;height="13px">&nbsp;
<div class="blank"></div>
<span class="badge badge-danger">100</span>
<img src="images/down.png" width="13px" ;height="13px">&nbsp;
<div class="blank"></div>
<span class="badge badge-danger">50</span>
<img src="images/eye.png" width="20px" ;height="20px">
<div class="blank"></div>
<span class="badge badge-danger">120</span>

</div>
</div>
</div>

这是我的 json 代码: (这是我的 .html 文件)

    <html ng-app="myClues">

<head>
<script data-require="angular.js@1.3.9" data-semver="1.3.9" src="https://code.angularjs.org/1.3.9/angular.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript">
var app = angular.module("myClues", []);
app.controller("MyController", function($scope, $http) {
$http.get("new1.json").success(function(result) {
$scope.Details = result.records;
});
});
</script>
</head>

<body ng-controller="MyController">
<div>
<ul>
<li ng-repeat="x in Details">
{{x.Name + ',' + x.City +',' + x.Country}}
</li>
</ul>
</div>
</body>

</html>

(下面是我的 .json 文件)

{
"records": [{
"Name": "CLUE 1",
"City": "Answer to clue 1",
"Country": "10 users rejected"
}, {
"Name": "CLUE 2",
"City": "Answer to clue 2",
"Country": "5 users rejected"
}]
}

当我运行页面时,我想在我创建的 HTML 文本框中显示 JSON 数据。我怎么做?我的 JSON 代码正确吗?

最佳答案

问题很简单,您正在循环 Details 而不是 Details.records :

<ul>
<li ng-repeat="x in Details.records">
{{x.Name + ',' + x.City +',' + x.Country}}
</li>
</ul>

关于javascript - 将 json 数据中的文本显示到我的 html 文本框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30075013/

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