Javascript 如何在视图中的数组值中重复ng

Javascript 如何在视图中的数组值中重复ng,javascript,arrays,json,angularjs,angularjs-ng-repeat,Javascript,Arrays,Json,Angularjs,Angularjs Ng Repeat,如何在视图中的ng repeat中对数组值使用ng repeat 我的第二次ng重复不起作用 generalDocument.documents的值为: [“14-10-2015.xls”、“15-10-2015.xls”、“16-10-2015.xls”] <div class="box-body table-responsive no-padding"> <table class="table table-hover table-striped">

如何在视图中的ng repeat中对数组值使用ng repeat

我的第二次ng重复不起作用

generalDocument.documents的值为:

[“14-10-2015.xls”、“15-10-2015.xls”、“16-10-2015.xls”]

 <div class="box-body table-responsive no-padding">
        <table class="table table-hover table-striped">
          <tr>
            <th>#</th>
            <th>Company</th>
            <th>Branch</th>
            <th>Document Type</th>
            <th>Desciption</th>
            <th>Reference Number</th>
            <th>Issue Date</th>
            <th>Expiry Date</th>
            <th>Documents</th>
          </tr>
          <tr ng-repeat="generalDocument in generalDocuments | orderBy: 'generalDocument.id' | filter: search">
            <td>{{ $index + 1 }}</td>
            <td>{{ generalDocument.company.company_name }}</td>
            <td>{{ generalDocument.branch.branch_name }}</td>
            <td>{{ generalDocument.document_type.document_type }}</td>
            <td>{{ generalDocument.description }}</td>
            <td>{{ generalDocument.reference_number }}</td>
            <td>{{ generalDocument.issue_date }}</td>
            <td>{{ generalDocument.expiry_date }}</td>
            <td>
                <div class="btn-group">
                  <button type="button" class="btn btn-default  btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                     Download <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu">
                    <li ng-repeat="document in generalDocument.documents track by $index">
                      <a href="">{{ document }}</a>
                    </li>
                  </ul>
                </div>
            </td>
          </tr>
        </table>
      </div>

我正在粘贴一个例子。请包括angular.min.js

<html>
    <head>
        <title>Angular JS Directives</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="angular.min.js"></script>
    </head>
    <body>
        <div ng-app="myApp" ng-controller="contrl">
            <p><input type="text" ng-model="city" /></p>
            <p>My City Name is: {{city}}</p>
            <p><input type="number" ng-model="qnty" /></p>
            <p><input type="number" ng-model="cost" /></p>
            <p>Total amount is : {{(qnty * cost)|currency}}</p>
            <p><input type="text" ng-model="test" /></p>
            <ul>
                <li ng-repeat="x in names | filter:test | orderBy:'country'">
                    {{(x.name | uppercase) + ',' + x.country}}
                </li>
            </ul>
        </div>
        <script>
            angular.module('myApp', []).controller('contrl', function ($scope) {
                $scope.qnty = 1;
                $scope.cost = 5;
                $scope.names = [
                    {name: 'Jani', country: 'Norway'},
                    {name: 'Hege', country: 'Sweden'},
                    {name: 'Kai', country: 'Denmark'}];
            });
        </script>
    </body>
</html>

角度JS指令

我的城市名是:{{City}

总金额为:{(qnty*成本)|货币}

  • {{(x.name |大写)+','+x.country}
角度。模块('myApp',[])。控制器('controll',函数($scope){ $scope.qnty=1; $scope.cost=5; $scope.names=[ {姓名:'Jani',国家:'Norway'}, {名称:'黑格',国家:'瑞典'}, {姓名:'凯',国家:'丹麦'}]; });
您确定“文档”属性中有数组吗?它看起来像是您发布的更新中的字符串

“JSON.parse”如果它是来自服务器的一个字符串,那么它将首先被调用。理想情况下,您应该更改服务器响应以发送阵列


希望能有所帮助

谢谢大家的帮助

generalDocument.document作为字符串从数据库中获取


我刚刚从服务器更改了模型,因此它将返回json数组而不是字符串值。现在ng repeat正常工作。

谢谢优素福。你贴的例子和我的情况不太一样。我的代码有两个ng重复。在我的代码中,第一个ng重复工作。第二个ng repeat不包含数组值而不是Json对象。你说的“不工作”是什么意思?它有什么作用?您可以创建一个示例JSFIDLE/PLUNK来演示吗?您在控制台中看到错误消息了吗?奇怪的是,起初我没有看到任何错误。哈哈,但现在有:Error:[ngRepeat:dupes]在中继器中不允许重复。听起来像是
generalDocument的值。文档
可能是字符串,而不是数组?如果您像yarons建议的那样在jsfiddle/plunker中复制它,这将非常有帮助。我在这里创建了一个精简的字符串,该字符串是有效的JSON,因此可以使用JSON.parse()将其转换为数组
<html>
    <head>
        <title>Angular JS Directives</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="angular.min.js"></script>
    </head>
    <body>
        <div ng-app="myApp" ng-controller="contrl">
            <p><input type="text" ng-model="city" /></p>
            <p>My City Name is: {{city}}</p>
            <p><input type="number" ng-model="qnty" /></p>
            <p><input type="number" ng-model="cost" /></p>
            <p>Total amount is : {{(qnty * cost)|currency}}</p>
            <p><input type="text" ng-model="test" /></p>
            <ul>
                <li ng-repeat="x in names | filter:test | orderBy:'country'">
                    {{(x.name | uppercase) + ',' + x.country}}
                </li>
            </ul>
        </div>
        <script>
            angular.module('myApp', []).controller('contrl', function ($scope) {
                $scope.qnty = 1;
                $scope.cost = 5;
                $scope.names = [
                    {name: 'Jani', country: 'Norway'},
                    {name: 'Hege', country: 'Sweden'},
                    {name: 'Kai', country: 'Denmark'}];
            });
        </script>
    </body>
</html>