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

标签 javascript jquery html json angularjs

这是我的文本框的 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/

相关文章:

php - 使用 jQuery AJAX 在表单提交时调用 php 页面

javascript - jquery mvc 4 获取一个列表项的所有数据

Html - 在更改页面大小时使表单响应

c# - 文本框的 Javascript 注入(inject)攻击预防

javascript - Bootstrap 菜单附加在带有品牌形象的滚动时收缩 - 移动行为

javascript - 显示具有 HTML 格式的 Backbone 集合

javascript - nodejs加载文件

javascript - Button.Click 事件未触发

javascript - 相对于另一个分区的 Bootstrap 列高度

php - MySQL 数据库/PHP - 从脚本生成 100 个联系人