【发布时间】:2020-04-07 21:17:35
【问题描述】:
我正在尝试组织一个下拉列表,该列表将向用户显示单个值,但也会在更改选择时传回一个数组对象。
目前我有一个名为 classificationresult 的数组,其中包含 3 个元素 CLASSIFICATION_NAME、GROUP_ID、GROUP_NAME。
当用户选择特定的 CLASSIFICATION_NAME 时,我想传回包含上面列出的所有 3 个元素的整个数组结果。
目前,除了在加载时在下拉框中显示 CLASSIFICATION_NAME 之外,以下代码适用于所有内容。单击后它会显示列表,但在单击之前它以空白开头。有任何解决这个问题的方法吗?我相信显示元素与 [ngValue] 相关联,但这也是我用来传回整个数组而不是只传回一个数组的方法。
任何帮助将不胜感激。
<p>Select Classification*</p>
<select [(ngModel)]="selectedClassification (ngModelChange)="changedClassification($event)">
<option *ngFor="let classificationresult of classificationresults" [ngValue]="classificationresult" >{{ classificationresult.CLASSIFICATION_NAME }}</option>
</select>
Summary -- I want my drop down list to always have a value shown to the user (value being the Classification Name) but when one is selected I want the entire array to pass to the changedClassification功能。此外,有时在用户从该页面上的其他下拉列表中进行选择后,它们也会变为空白,但如果再次选择它们,它们将填充。
【问题讨论】:
-
如果组件中已经有数据,为什么不直接过滤数据并将其转换为
ngModelChange中的数组? -
这帮我解决了,非常感谢。
标签: html angular typescript angular2-ngmodel