我在使用带有 ngx-datatable 的下拉列表时遇到问题。当用户从下拉列表中选择一个项目时,所有其他下拉列表都将设置为该选定项目。我试过使用
let-rowIndex=“rowIndex”
运气不好。
这是我目前所拥有的。
<ngx-datatable
class="material"
[rows]='bankingStatements'
[columnMode]="'force'"
[headerHeight]="50"
[footerHeight]="50"
[rowHeight]="'auto'"
[limit]="10">
<ngx-datatable-column [width]="50" name="Paid by..."
[sortable]="true" [draggable]="false">
<ng-template let-row="row" let-rowIndex="rowIndex" ngx-datatable-cell-template>
<md-select class="paid-in-select" [(ngModel)]="selectedItem" (change)="checkIfCustomerExists(rowIndex)" name="{{rowIndex}}" id="customers-{{rowIndex}}">
<md-option *ngFor="let cust of paidInSelect" [value]="cust">
<div *ngIf="cust.customers?.customer_name; else elseOther">
{{cust.customers?.customer_name}}
</div>
<ng-template #elseOther>
{{cust?.customers}}
</ng-template>
</md-option>
</md-select>
</ng-template>
</ngx-datatable-column>
</ngx-datatable>
任何帮助将不胜感激。
最佳答案
这是因为每一行的选择都设置为相同的 [(ngModel)]
你需要将每一行绑定(bind)到不同的 ngModel 对象。例如一个数组:
[(ngModel)]="selectedItem[rowIndex]"
关于javascript - 从下拉列表中选择一个项目将所有下拉列表设置为相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46340614/