在* ngFor迭代中,如果值等于特定值,则不使用Angular4列出列表中的值。
我的模板:
<div class="desktop-list btn-group-vertical show-cat">
<button class="list-group-item list-group-item-action cat-btn" *ngFor='let category of categories' (click)="getCatName($event)">{{category}}<i class="glyphicon glyphicon-chevron-right"></i></button>
</div>
<div class="mobile-select show-cat">
<select class="mobile-select show-cat" [ngModel]="selectedCat" (ngModelChange)="change($event)" name="category" id="cat-column" placeholder="Select a Category">
<option [ngValue]="category" class="cat-btn" *ngFor='let category of categories'>{{category}}</option>
</select>
</div>
组件getCategories功能:
getCatgegories(masterProduct: number) {
this.service.getCatgegories(masterProduct)
.subscribe(response => {
this.categories = response.catList;
this.categories.splice(0,0, 'Select a Category');
this.masterName = response.name;
});
}
我想检查类别是否='选择一个类别',如果它返回true,它将不会在按钮列表中显示该项目。我觉得这应该是一件容易实现的事情,但却找不到解决方案。 非常感谢任何帮助,谢谢。
答案 0 :(得分:2)
作为一个简单的解决方案:
<div class="desktop-list btn-group-vertical show-cat">
<ng-template ngFor let-category [ngForOf]="categories">
<button class="list-group-item list-group-item-action cat-btn" *ngIf="category !=='Select a Category'" (click)="getCatName($event)">{{category}}<i class="glyphicon glyphicon-chevron-right"></i>
</button>
</ng-template>
</div>
希望它有助于你:)
答案 1 :(得分:0)
必须有更好的方法来处理这个概念,但如果你想要的只是不显示该特定情况的标签,那么你可以将你的标签包装在span
中并为特定情况隐藏它
<div class="desktop-list btn-group-vertical show-cat">
<button class="list-group-item list-group-item-action cat-btn" *ngFor='let category of categories' (click)="getCatName($event)">
<span *ngIf="category !== 'Select a Category'">{{category}}<i class="glyphicon glyphicon-chevron-right"></i></span>
</button>
</div>
答案 2 :(得分:0)
我认为您可以使用public class OpportunityMaint_Extension : PXGraphExtension<OpportunityMaint>
{
public override void Initialize()
{
Report.AddMenuAction(QuoteReport);
Report.MenuAutoOpen = true;
}
public PXAction<CROpportunity> Report;
[PXButton]
[PXUIField(DisplayName = "Reports", MapEnableRights = PXCacheRights.Select)]
protected void report()
{ }
public PXAction<CROpportunity> QuoteReport;
[PXButton]
[PXUIField(DisplayName = "Quote", MapEnableRights = PXCacheRights.Select)]
protected IEnumerable quoteReport(PXAdapter adapter)
{
var reportID = "IOCR6410";
List<CROpportunity> list = adapter.Get<CROpportunity>().ToList();
Base.Save.Press();
int i = 0;
Dictionary<string, string> parameters = new Dictionary<string, string>();
foreach (CROpportunity opp in list)
{
parameters["CROpportunity.OpportunityID" + i.ToString()] = opp.OpportunityID;
i++;
}
if (i > 0)
{
throw new PXReportRequiredException(parameters, reportID, string.Format("Report {0}", reportID));
}
return list;
}
}