我有我的模塊中的以下數組中Angular.js
:採用NG-重複表格格式
$scope.hsbody = []; //Data array
$scope.hsresult = []; //Data array
$scope.hsProcess = []; //Boolean array
$scope.hssuccess = []; //Boolean array
$scope.hsfailure = []; //Boolean array
$scope.hsExpand = []; //Boolean array
$scope.hsExpandUser = []; //Boolean array
我想表明我的HTML頁面數組項:
hsresult
hsbody
hsresult
hsbody
and so on..
所以我做以下內容:
<div>
<pre>
<table class="table table-condensed">
<tr ng-repeat="hs in hsbody track by $i" ng-show="hsProcess[i] && !hssuccess[i] && !hsfailure[i]" class="warning"><td><div class="glyphicon"></div>{{hsbody}}</td></tr>
<tr ng-show="hssuccess" ng-repeat="highstate in hsbody track by $i" class="success"><td><div class="glyphicon" ng-show="!hsExpand[i]"></div><div class="glyphicon" ng-show="hsExpand[i]"></div>{{ hsresult[i] }} </td></tr>
<tr ng-show="hsfailure" ng-repeat="hs in hsbody track by $i" class="danger"><td><div class="glyphicon" ng-show="!hsExpand"></div><div class="glyphicon" ng-show="hsExpand[i]"></div>{{ hsresult[i] }}</td></tr>
<tr ng-repeat="hs in hsbody track by $i" ng-show="(hsProcess[i] && hsExpand[i]) || (hsExpand[i] && hsfailure[i])" class="active"><td><pre>{{ hsbody[i] }}</pre></td></tr>
</table>
</pre>
</div>
問題是我的HTML中沒有顯示任何內容。但是當我擺脫ng-repeat
並使用i=0
時,我可以看到這些值。
看來我沒有正確使用ng-repeat
,但我不知道我錯在哪裏。
whats'$ i' in track by? – 2015-04-05 06:43:27
@ K.Toress:你能澄清一下這個問題嗎?我所要做的就是將所有物品放入hsbody中,並使用'$ i'索引來遍歷它們。我知道'hsbody.length = hsresult.result = hsProcess.length =等等,所以我使用每個數組的'$ i'值。 – MiddleWare 2015-04-05 06:56:44
爲什麼你不恰當地重組控制器中的數據?這就是我認爲你應該做的。 – Wio 2015-04-05 07:01:27