gpt4 book ai didi

javascript - AngularJS - 下拉列表不保留所选值

转载 作者:行者123 更新时间:2023-11-27 22:40:42 25 4
gpt4 key购买 nike

在我的 AngularJS Web 应用程序中,

笨蛋:https://plnkr.co/edit/x9uIx5Inkxxt3fqttkkK?p=preview

我的下拉菜单之一(第一个)不保留所选值。html 代码片段如下。

我知道这与映射有关 ng-model="entityPropertyType.propertyId"

entityPropertyType 是列表中的迭代值。

HTML

        <div class="form-group" ng-repeat="entityPropertyType in advancedSearch.entityPropertyTypes" >

<label class="control-label col-md-1">Business Card</label>
<div class="col-md-2">
<select class="form-control" ng-model="entityPropertyType.propertyId"
ng-change="businessCardSelected($index, entityPropertyType.propertyId)" >
<option value="">Please select</option>
<option ng-repeat="property in businessCards" value="{{property.propertyId}}">{{property.propertyLabel}}</option>
</select>
</div>


</div>

最佳答案

您永远不应该使用 ngRepeat 来呈现选择选项。使用ngOptions指令:

<select class="form-control" 
ng-options="property.propertyId as property.propertyLabel for property in businessCards"
ng-model="entityPropertyType.propertyId"
ng-change="businessCardSelected($index, entityPropertyType.propertyId)">
<option value="">Please select</option>
</select>

演示: https://plnkr.co/edit/v6KbJSkqu5XNz2LUfbrK?p=preview

关于javascript - AngularJS - 下拉列表不保留所选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com