【发布时间】:2014-04-14 13:16:08
【问题描述】:
我有 2 个选择和一个具有功能的按钮。我想检查是否选择了位置,然后执行代码的位置部分,如果选择了分配,则执行代码的分配部分。如果两者在 api 中都为空,则它可以工作;),然后我可以更改其中一个。
$scope.edit_location = function() {
for(var i = 0; i < $scope.inventories.length; i++) {
if($scope.currentInventory.location){
console.log('I am in location');
var copySelectedInv = Restangular.copy($scope.currentInventory);
copySelectedInv.customPUT({location: $scope.currentInventory.location, assigned: null, tags: $scope.inventories[i].tags});
}else if ($scope.currentInventory.assigned){
console.log('I am in assigned');
var copySelectedInv2 = Restangular.copy($scope.currentInventory);
copySelectedInv2.customPUT({location: null, assigned: $scope.currentInventory.assigned, tags: $scope.inventories[i].tags});
}
}
};
我的模板选择
<select class="input-medium form-control" ng-model="currentInventory.location">
<option value="">Choose location</option>
<option value="{{location.resource_uri}}" ng-repeat="location in locations">{{location.name}}</option>
</select>
<h5>Assigne to employee</h5>
<select class="input-medium form-control" ng-model="currentInventory.assigned">
<option value="">Choose location</option>
<option value="{{user.resource_uri}}" ng-repeat="user in users">{{user.first_name + ' ' + user.last_name}}</option>
</select>
<button class="btn tbn-lg btn-success" ng-click="edit_location()">
【问题讨论】:
-
您需要两个选定的值互斥,对吗?检查我更新的答案。
标签: javascript angularjs restangular