【发布时间】:2017-02-28 14:58:31
【问题描述】:
中心名称下拉代码:
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-6">
<label>Centre Name<span class="required">*</span></label>
<div class="form-group">
<select data-selectpicker class="selectpicker" name="location"
data-ng-model="user.location_id" required>
<option value="">Select</option>
<option data-ng-repeat="location in locationValues"
value="{{location.location_id}}">{{location.name}}</option>
</select>
<span class="input-error-span" data-ng-show="editUser.$submitted || editUser.location.$touched || editUser.location.$dirty">
<span data-ng-show="editUser.location.$error.required">{{'REQUIRED_CENTRE' | translate}}</span>
</span>
</div>
</div>
我的应用程序有一个下拉菜单和一个多选框。两者的值都取自同一个数据库。
现在的问题是用户需要先从下拉列表中选择选项。此选择应反映在同一页面上的多选上。表示从下拉框中选择的任何选项都必须是用户无法更改的多选中的默认选择。
请帮我找出解决办法。
可用中心多选框代码:
<div class="col-lg-12 col-md-12 col-sm-4 col-xs-4" data-ng-if="user.role_id == '2'">
<label>Available In Centre<span class="required">*</span></label>
<div class="form-group">
<select name="location" class="form-control" multiple data-ng-multiple="true" data-ng-model="viewlocation" data-ng-options="obj.name for obj in locationValues" data-ng-init="obj.location_id = user.location_id" required>
</select>
<span class="input-error-span" data-ng-show="editUser.$submitted || editUser.location.$touched">
<span data-ng-show="editUser.location.$error.required">{{'REQUIRED_VIEWABLE_LOCATION' | translate}}</span>
</span>
</div>
</div>
现在,如果用户从下拉列表中选择选项,则应在多选框中选择该选项。并且用户无法更改它,直到他/她更改下拉菜单中的选项。
【问题讨论】:
-
用您已经选择的特定数据填充该选择元素的 ng-model 属性。它将显示所有选定的元素,如果您已经选择了它,则将其禁用。
-
在更改下拉值时,只需发出 http 请求即可返回多选框的准确数据。如果你分享你的代码,解释一下会很有帮助。
标签: angularjs spring hibernate