【发布时间】:2021-05-17 04:33:28
【问题描述】:
从表行的下拉列表中选择一个选项后,我调用 api 将字符串列表放入该行的下拉字段中,但完整的列会获取该行的选项。我只希望对特定的行进行操作。如何在 Angular js 中实现这一点。 例如: 如果我选择 India 作为员工的 countryName,我会从 api 获取 CountryStates,但 CountryStates 会填充到该表的完整列中。所以我希望它填充到那个特定的行。 你能帮我么。 这是我的代码
<tr ng-repeat = "data in arrayOfEmp" id = {{$index}}>
<td>
<select ng-model="data.countryName" ng-options="country for country in countries" ng-change ='getStates($index)' unselectable="on">
{{data.countryName}}
</select>
</td>
<td>
<select ng-model="data.stateName" ng-options="st for st in stateNames" ng-change ='changeButtonStatus()' unselectable="on">
{{data.stateName}}
</select>
</td>
这里是angularjs控制器的代码
$scope.arrayOfEmp = [{
empID : '093024',
countryName : 'India',
},{
empID : '093214',
countryName : 'USA',
},{
empID : '0935614',
countryName : 'Dubai',
}];
$scope.getStates = function(id)
{ $scope.stateNames = [];
http({
method:'GET'
url:'getStateNames'
params: {country : $scope.arrayOfEmp[id].countryName}
}).then(function onSuccess(response){
$scope.stateNames = response.data;
},function onError(){
console.log(response.data);
});
}
[![enter image description here][1]][1]
【问题讨论】:
标签: javascript html angularjs dom parent-child