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

时间:2023-01-28 12:15:17

Here is my html text for my text-box :

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

Here is my json code: (This is my .html file)

这是我的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>

(Below is my .json file)

(下面是我的.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"
  }]
}

When I run the page I want to display the JSON data in my HTML text boxes which I have created. How do I do that? Is my JSON code correct?

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

1 个解决方案

#1


The problem is simply that you're looping over Details instead of Details.records :

问题只是你循环使用Details而不是Details.records:

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

#1


The problem is simply that you're looping over Details instead of Details.records :

问题只是你循环使用Details而不是Details.records:

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