【发布时间】:2017-11-07 11:26:14
【问题描述】:
我有一个包含产品列表的表格。在表格下方,我有一个输入条形码的文本字段,如果找到条形码,则应突出显示表格中的匹配行。我已经阅读了许多类似的场景,据我所知,我正在做我应该做的一切。我可以在谷歌开发控制台中看到我输入的条形码与我表中当前唯一的产品匹配但是由于某种原因没有应用 css...知道我在这里做错了什么吗?/我怎么能去修复它?
我的CSS:
.found {
background-color: green;
}
我的 html 表格和输入字段:
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Price</th>
<th>Qty</th>
<th>Barcode</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of ticket.items" [class.found]="item.Barcode === spotCheckBarcode">
<td>{{item?.ProductDetail_Name}}</td>
<td>{{item?.Amount}}</td>
<td>{{item?.Qty}}</td>
<td>{{item?.Barcode}}</td>
</tr>
</tbody>
</table>
<form role="form" [formGroup]="spotCheckForm" (ngSubmit)="spotCheck(spotCheckForm.value.itemBarcode)">
<input class="form-control" type="tel" placeholder="Enter item barcode" [formControl]="spotCheckForm.controls['itemBarcode']">
<button class="btn btn-block" [disabled]="!spotCheckForm.controls['itemBarcode'].valid && busy"><span class="glyphicon glyphicon-search"></span> Search</button>
</form>
//设置spotCheckBarcode的我的ts组件函数
spotCheck(itemBarcode: number) {
let found: boolean = false;
for (var i: number = 0; i < this.ticket.items.length; i++) {
if (itemBarcode === this.ticket.items[i].Barcode) {
console.log('found!');
found = true;
this.spotCheckBarcode = itemBarcode;
}
}
if (found == false) {
console.log(`found in if statement: ${found}`);
this.showError("Item not found on ticket");
}
}
【问题讨论】:
-
你试过了吗:.found td { background-color: green; }
-
你能创建一个快速的 plunker 以便更容易弄清楚发生了什么。
-
@techLove 做到了!!!请添加它作为答案,为什么我必须将它应用于列和行?
标签: css html twitter-bootstrap angular