Please help:
Would like to place buttons for a jSon data, 4 rows and 3 column(total 12 buttons) with
1) button name: as jSon key ex "jan" etc (button names from Jan to Dec)
2) button color: blue for jSon value=="Yes" and red when value=="No". Also,
数据如下: var data = { "扬":"是&#34 ;, " 2月":"不", " March":"是", " April":" No", " May":"是", "六月":"否", "七月":"是", " 8月":"不", " 9月":"是", " 10月":"不", " 11月":"是", " Dec":" No" }
</ion-content>
<div class="row" ng-repeat="(key, value) in data" >
<div ng-if="$index%4==0" class="row">
<div class="col">
<span ng-if="value=='Yes'" >
<button id={{$index}} class="button button-royal" >{{key}}</button>
</span>
<span ng-if="value=='No'" >
<button id={{$index+}} class="button button-assertive" >{{key}}</button>
</span>
<span ng-if="value=='Yes'" >
<button id={{$index+1}} class="button button-royal" >{{key[$index+1]}}</button>
</span>
<span ng-if="value=='No'" >
<button id={{$index+1}} class="button button-assertive" >{{key[$index+1]}}</button>
</span>
<span ng-if="value=='Yes'" >
<button id={{$index+2}} class="button button-royal" >{{key[$index+2]}}</button>
</span>
<span ng-if="value=='No'" >
<button id={{$index+2}} class="button button-assertive" >{{key[$index+2]}}</button>
</span>
<span ng-if="value=='Yes'" >
<button id={{$index+3}} class="button button-royal" >{{key[$index+3]}}</button>
</span>
<span ng-if="value=='No'" >
<button id={{$index+3}} class="button button-assertive" >{{key[$index+3]}}</button>
</span>
</div>
</div>
</div>
</ion-content>
答案 0 :(得分:0)
<div ng-app="myApp" ng-controller="myCtrl">
<div class="row" ng-repeat="data in datas" ng-if="$index % 4 === 0">
<div class="col col-25" ng-if="$index < 12">
<button ng-class="(datas[$index].color=='Yes'? 'button button-positive' : 'button')">{{datas[$index].month}}</button>
</div>
<div class="col col-25" ng-if="$index + 1 < 12">
<button ng-class="(datas[$index+1].color=='Yes'? 'button button-positive' : 'button')">{{datas[$index+1].month}}</button>
</div>
<div class="col col-25" ng-if="$index + 2 < 12">
<button ng-class="(datas[$index+2].color=='Yes'? 'button button-positive' : 'button')">{{datas[$index+2].month}}</button>
</div>
<div class="col col-25" ng-if="$index + 3 < 12">
<button ng-class="(datas[$index+3].color=='Yes'? 'button button-positive' : 'button')">{{datas[$index+3].month}}</button>
</div>
</div>
</div>
$scope.datas = [{ "month":"Jan","color":"No"},
{"month":"Feb","color":"Yes"},
{"month":"March","color":"No"},
{"month":"April","color":"No"},
{"month":"May","color":"No"},
{"month":"June","color":"Yes"},
{"month":"July","color":"No"},
{"month":"Aug","color":"Yes"},
{"month":"Sept","color":"Yes"},
{"month":"Oct","color":"No"},
{"month":"Nov","color":"Yes"},
{"month":"Dec","color":"Yes"},
];