如何解决当值是对象类型时,离子选择不显示所选选项
我将一个对象绑定到select-option的value属性。
My Jsp Code:
<logic:iterate id="rep" name="custApplReport" property="customerJsp">
<tr>
<td CLASS="text-center v-midalign" id="aaa" style="word-wrap:break-word;">
<logic:notEmpty name="rep" property="componentGroupName">
<html:link href="#" onclick="javascript:fnEditCompGrpInCOC1()"><bean:write name="rep" property="componentGroupName" /></html:link>
</logic:notEmpty>
<logic:empty name="rep" property="componentGroupName">
</logic:empty>
</td>
</tr>
</logic:iterate>
打开弹出窗口时,不会显示所选值。
解决方法
您的数据绑定失败,因为ion-select-option
中的value属性包含一个字符串,而ion-select
中的value属性包含一个对象。
您需要绑定ion-select-option的value属性。
<ion-select-option [value]="{key:'abc',value:'ABC'}">ABC</ion-select-option>
我建议您不要将对象用作ion-select-option
的值。
由于对象中包含键和值,因此您应该编写更清晰的代码。将关键部分保留在ion-select-option
的value属性中。
<ion-item>
<ion-label>Choose</ion-label>
<ion-select [(ngModel)]="myKey">
<ion-select-option value="abc">ABC</ion-select-option>
<ion-select-option value="pqr">PQR</ion-select-option>
<ion-select-option value="xyz">XYZ</ion-select-option>
</ion-select>
</ion-item>
在组件中,声明变量myKey并为其分配一个值。
myKey='abc';
这是角度2数据绑定的示例。在此处阅读更多信息:https://codecraft.tv/courses/angular/forms/template-driven/#_two_way_data_binding
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。