gpt4 book ai didi

javascript - ng-重复 : How to set property multiple in select

转载 作者:行者123 更新时间:2023-12-03 06:42:52 27 4
gpt4 key购买 nike

重复时我有对象(arr),他有属性charType:selectmultiple

我想如果charType“select”看到正常选择,但如果charType“multiple”请参阅选择多个。

示例:

如果对象(arr)有5个结果0,1,2是charType'select'并且3,4charType是'multiple'。我想看看0 选择1 选择2 选择3 多选4 多选

<div class="form-group" ng-repeat="att in arr track by $index">
<div class="col-md-3">
<label for="phone" ng-model="type">{{att.name}}</label>
</div>
<div class="col-md-9">
({{att.charType}})
<select class="form-control" ng-model="charObj.charactValue[att.businessassetID + $index]" ng-if="att.charType == 'select' ? 'multiple' : 'multiple=true'">
<option ng-repeat="itemss in att.value track by $index" value="{{itemss}}">{{itemss}}</option>
</select>
<div class="text-center"><a class="insertStore" data-toggle="modal" data-target="#addCharacteristicValue" ng-click="getObj(att)">Добави</a>
</div>

</div>
</div>

最佳答案

这是一个工作片段:

  • 在选项标签中使用 ng-options 而不是 ng-repeat
  • 按索引删除轨道使选择失败
  • 使用简单的 ng-if 生成两个不同的选择。

似乎没有 ng-multiple 指令,所以我采用了 ng-if 解决方法。

angular.module("app", []).controller("ctrl", function($scope){
$scope.arr = [{charType:'select', name:'select', value:[1, 2]},{charType:'multiple', name:'multiple', value:[1,2]}];
$scope.charObj = {characterValue:{}};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>



<div ng-app="app" ng-controller="ctrl">
<div class="form-group" ng-repeat="att in arr track by $index">
<div class="col-md-3">
<label for="phone" ng-model="type">{{att.name}}</label>
</div>
<div class="col-md-9">
({{att.charType}})
<select ng-if="att.charType == 'select'" class="form-control" ng-model="charObj.charactValue[att.businessassetID + $index]" ng-options="itemss for itemss in att.value">
</select>
<select ng-if="att.charType != 'select'" multiple class="form-control" ng-model="charObj.charactValue[att.businessassetID + $index]" ng-options="itemss for itemss in att.value">
</select>

</div>
</div>
selected : {{charObj.charactValue}} <br />
</div>

关于javascript - ng-重复 : How to set property multiple in select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37875641/

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