大家好我正在使用angularjs ng-repeat我有复选框和下拉列表绑定它现在我需要的是当我更改下拉值时意味着自动复选框将根据下拉选择进行检查
<div ng-repeat="BFMaterialStream in BFMaterialStreams">
<input type="checkbox" ng-change="checkchange(BFMaterialStream.MaterialStream,$index)"
ng-model="selection.ids[BFMaterialStream.MaterialStream]" name="group" id="BFMaterialStream.MaterialStream" />
{{BFMaterialStream.MaterialStream}}
<select id="MaterialElevator" tabindex="7" required typeof="text" name="Elevator"
form="DistanceMatrixFormId" class="form-control"
ng-model="ViewGetBUMaterialStream.ToElevator"
>
<option value=''>Select</option>
<option ng-repeat="ViewGetBUMaterialStream in ViewGetBUMaterialStreams "
value="{{ViewGetBUMaterialStream.ToElevator}}"
>
{{ViewGetBUMaterialStream.ToElevator}}
</option>
</select>
</div>
答案 0 :(得分:1)
检查小提琴的工作答案
https://jsfiddle.net/athulnair/pzuetsx1/2/
$scope.checkLine = function(index) {
$scope.lines[index].selected = true;
}
<div ng-repeat="line in lines">
<input type="checkbox" ng-model="line.selected" /> {{line.text}}
<select required typeof="text" class="form-control" ng-change="checkLine($index)" ng-model='line.text'>
<option value='0'>Select</option>
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
</select>
</div>
答案 1 :(得分:1)
在<select>
上使用ng-change并在指定的函数中将checkbox的ng-model值设为true。
在复选框HTML
中 <input type="checkbox" ng-change="checkchange(BFMaterialStream.MaterialStream,$index)"
ng-model="selection.ids[BFMaterialStream.MaterialStream]" name="group" id="BFMaterialStream.MaterialStream"
ng-true-value="true" ng-false-value="false"/>
在选择HTML
中 <select id="MaterialElevator" tabindex="7" required typeof="text" name="Elevator"
form="DistanceMatrixFormId" class="form-control" ng-model="ViewGetBUMaterialStream.ToElevator"
ng-change="SetCheckBoxTrue(BFMaterialStream.MaterialStream)">
JS中的:
$scope.SetCheckBoxTrue= function (MaterialStream) {
$scope.selection.ids[MaterialStream] = true;
}