![](/img/trans.png)
[英]How to filter ng-repeat with values NOT IN another array in Angular?
[英]How to ng-repeat in array values in Views
如何在視圖中ng-repeat內的數組值上使用ng-repeat?
我的第二個ng-repeat不起作用。
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>
更新:我通過$ index添加了音軌 ,現在循環了。 但是每個字符循環。
更新:我console.log generalDocument和generalDocument.document是從數據庫中獲取的
document: "["EK 845 FDX 20150906 00001 CARGO1.xls","EK 845 FDX 20150906 00004 MOH.xls","EK 847 FDX 20150811 000010 COMMPERSONAL3.xls"]"
我正在粘貼一個例子。 請包括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>
您確定“文檔”屬性中有一個數組嗎? 它看起來像您發布的UPDATE中的字符串。
如果它作為字符串來自服務器,則首先“ JSON.parse”。 理想情況下,您應該更改服務器響應以發送數組。
希望能幫助到你
謝謝大家的幫助。
generalDocument.document是從數據庫中以STRING提取的。
我剛剛從服務器更改了模型,因此它將返回json數組而不是字符串值。 現在ng-repeat可以正常工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.