【发布时间】:2020-02-19 16:45:03
【问题描述】:
<table id="DataTable" border="1" ALIGN="center">
<tr ALIGN="center">
<th>name</th>
<th>address</th>
<th>number</th>
<th>type</th>
</tr>
<tr class="tcat" *ngFor="let item of Tdata; let i = index;">
<td class="name">{{item.name}}</td>
<td class="address">{{item.address}}</td>
<td class="number">{{item.number}}</td>
<td class="type" ALIGN="center"
*ngIf="!item.type || item.type == null || item.type == 'undefined'">
<select (click)="jsFunction();">
<option value="" disabled selected>Select your option</option>
<option *ngFor="let currentData of dropdata">
{{currentData.type}}</option>
</select>
</td>
</tr>
</table>`
.ts 文件
dropdata:any;
Tdata = [
{ name: "xyz", address: "abc", number: 12345, type: null },
{ name: "xyz1", address: "abc1", number: 78900, type: null },
{ name: "xyz2", address: "abc2", number: 7400, type: null }
];
selecttedDropData = {};
jsFunction() {
// called second api;
this.dropdata = [
{ number: "12345", type: "customer" },
{ number: "12345", type: "dealer" },
{ number: "12345", type: "client" },
{ number: "12345", type: "master" }
];
}
在页面加载时,我显示了一个表格,并在列类型中添加了 一个下拉菜单。
点击每个下拉菜单时,我会调用
API并获取要填充的数据选项。唯一的问题是当我单击第一个下拉菜单或任何其他下拉菜单并选择任何选项之后,我选择第二个或任何其他下拉菜单,因此所有选定的下拉列表值都会更改等等。
找不到任何有用且正确的答案。请帮帮我。
非常感谢。
【问题讨论】:
-
当您更改选项时,是否需要通过获取的数据影响已选择的下拉菜单?
-
第二个api获取不同的值,对吧?
-
点击时的每个下拉菜单都有一个 API 调用。第二个 API 每次都获取不同的值。表格中有多个下拉列表,当我选择一个下拉列表时,所有选定的下拉列表都会更改
-
如果我的回答对您有帮助,请点赞并点击勾选以帮助寻求此类问题的人
标签: javascript html arrays angular datatable