【发布时间】:2019-11-14 09:25:27
【问题描述】:
我的 Angular 7 应用程序中有一个 html,我在其中为每一行显示相同的下拉列表。选择一个下拉菜单正在更改另一个下拉菜单的值。如何使选择对该特定下拉菜单唯一。
html
<div class="upload-table">
<table id="table1" class="center" >
<tbody class="upload-name-style">
<tr *ngFor="let item of files; let i=index">
<td> <input kendoTextBox [(ngModel)]="item.relativePath" style="width: 350px" /></td>
<td><kendo-dropdownlist style="width:350px" [(ngModel)]="selectedDocumentItem" [data]="DocumentTypes"
[filterable]="false" textField="Name" valueField="Id">
</kendo-dropdownlist></td>
</tr>
</tbody>
</table>
</div>
组件代码
DocumentTypes: any = {};
selectedDocumentItem: { 'Id': any; 'Name': any; };
public getDocumentTypes() {
this.documentUploadService.getDocumentTypes()
.subscribe(data => {
this.DocumentTypes = data;
this.DocumentTypesForDropDown = this.DocumentTypes.map(x => x.Name);
this.getDocumentUploadDetails();
this.setGridOptions();
this.setColumns();
},
err => {
this.Error = 'An error has occurred. Please contact BSG';
},
() => {
});
}
【问题讨论】:
-
如果他们都共享相同的模型,那么他们当然都选择相同的数据。您可以为不同的“selectedDocumentItem”设置一堆值,列表中的每个项目一个,但最好让您的列表成为一个组件,它可以根据需要重复多次。该组件将很好地包装自己的数据。
-
和你对输入框做的一样:它的模型是
item.relativePath,所以每个项目都有自己的relativePath。由于您还希望每个项目都有自己的选定文档,因此下拉列表的模型应该是item.selectedDocumentItem,而不是selectedDocumentItem。 -
我试过 item.selectedDocumentItem,它似乎工作
标签: angular