我是angularJS的新手。我有以下代码:
<div class="col-sm-3 col-xs-6" ng-repeat="image in gallery | limitTo:'4'">
<a href="#"><img ng-src="
<?php echo '...' ?>{{pack.hotels.current.images[$index+1].path}}"
alt="Image" class="img-responsive"></a>
</div>
目前我有一个对象数组,它们有2个属性:type和path。在ng-repeat中,我遍历所有对象。我想只迭代数组中具有类型===&#34; GEN&#34;
属性的对象调试时,我运行:
pack.hotels.current.images.forEach(function(item, count){
if(item.type === "HAB")
console.log(item)
})
如何重写ng-repeat语句,使其仅通过具有 type =&#34; GEN&#34; 属性的元素进行迭代?我应该使用哪种过滤器?谢谢!
答案 0 :(得分:2)
像这样使用ng-repeat:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var range = sheet.getRange("B13");
var data = range.getValue();
var a=(data*.13);
var b=(data*.14);
var c=(data*.15);
if(a<=150)
{(X=150);}
if(a>150)
{(X=a);}
if(b<=150)
{(Y=150);}
if(b>150)
{(Y=b);}
if(c<=150)
{(Z=150);}
if(a>150)
{(Z=c);}
return X;
}
答案 1 :(得分:1)
只需添加过滤器filter: {type:'GEN'}
HTML
<div class="col-sm-3 col-xs-6" ng-repeat="image in gallery | filter: {type:'GEN'}| limitTo:'4'">
<a href="#"><img ng-src="
<?php echo '...' ?>{{pack.hotels.current.images[$index+1].path}}"
alt="Image" class="img-responsive"></a>
</div>