<div class="row" ng-repeat="data1 in data.results ">
<div class="col" >{{$index}}</div>
<div class="col">{{data1.item_name}}</div>
<div class="col">
<select ng-model = "value" ng-change = "callUsers(value)">
<option value = "" selected>Choose a process</option>
<option ng-repeat='proces in data.process' >{{proces.name}}</option>
</select>
</div>
<div class="col">
<select ng-model = "value1" ng-change = "selectedEmployee(value1)">
<option value = "" selected>Select User</option>
<option value ="" ng-repeat='employee in employeeList' >{{employee.firstName}}</option>
</select>
</div>
</div>
控制器代码:
$scope.callUsers = function(code){
for(var i=0; i<$scope.data.process.length; i++){
if($scope.data.process[i].name == code){
var param = {
'process' : $scope.data.process[i].code
}
AssignOrderService.getEmployees(param)
.success(function(data) {
$ionicLoading.hide();
if(data.length>0){
$scope.employeeList = data;
}
}).error(function(data) {
$ionicLoading.hide();
});
}
}
}
$scope.selectedEmployee = function (employee){
var myIsolatedEmployee = angular.copy(employee);
console.log(myIsolatedEmployee);
}
当我更改任何流程时,我会获得员工列表并通过employeeList显示。
但问题是,由于employeeList范围内有很多select语句,当我更改进程的一个select选项值时,employeeList会自动更新。
如何处理?
由于
答案 0 :(得分:0)
问题是您没有按照自己的意愿隔离员工名单。因此,您必须在其上下文中声明列表和内容(即data1
),它应该可以正常工作。
在html上,您必须添加data1
以识别类似ng-change="callUsers(value, data1)"
的上下文。此外,现在您必须从现在被隔离的data1
迭代员工列表,如ng-repeat='employee in data1.employeeList'
。
<div class="row" ng-repeat="data1 in data.results ">
<div class="col" >{{$index}}</div>
<div class="col">{{data1.item_name}}</div>
<div class="col">
<select ng-model="value" ng-change="callUsers(value, data1)">
<option value="" selected>Choose a process</option>
<option ng-repeat='proces in data.process' >{{proces.name}}</option>
</select>
</div>
<div class="col">
<select ng-model = "data1.value1" ng-change="selectedEmployee(value1)">
<option value = "" selected>Select User</option>
<option value ="" ng-repeat='employee in data1.employeeList' >{{employee.firstName}}</option>
</select>
</div>
</div>
在控制器上,不是将员工列表绑定到主范围,而是将其绑定到data1
,这是循环的隔离上下文。
$scope.callUsers = function (code, data1) {
//$scope.employeeList = [];
for (var i = 0; i < $scope.data.process.length; i++) {
if ($scope.data.process[i].name == code) {
var param = {
'process': $scope.data.process[i].code
}
AssignOrderService.getEmployees(param)
.success(function (data) {
$ionicLoading.hide();
console.log(data);
if (data.length > 0) {
data1.employeeList = data;
}
}).error(function (data) {
$ionicLoading.hide();
});
}
}
}