2014-03-27 74 views
0

我想在我的api上更改,selected: true當我點擊當前庫存。更改爲true時angularjs

我可以這樣做嗎?

app.controller('InventoryDetailCtrl', function($scope, Inventory, Assigned, Tags, Restangular, currentInventory) { 
$scope.inventories = new Inventory().query().$object; 

$scope.selected = function(id) { 
    for(var i = 0; i < $scope.inventories.length; i++){ 
     if($scope.inventories[i].id == id){ 
      console.log(id); 
      var selectedInventory = Restangular.copy($scope.currentInventory); 
      selectedInventory.customPUT({selected: True }); 
     } 
    } 
}; 

}); 

在這裏,我得到了我的國家,在那裏我得到我的當前庫存

.state('inventory.detailview',{ 
url:'/detailview', 
    views: { 
     "main": { 
      controller: 'InventoryDetailCtrl', 
      templateUrl: 'inventory/detail.tpl.html' 
     } 
    }, 
    resolve: { 
    currentInventory: function($stateParams, Inventory){ 
     return new Inventory().get($stateParams.id).$object; 
     } 

,並在我的模板我喜歡這個

<div ng-repeat="inventory in inventories"> 
    <a href="" ng-click="selected(inventory.id)">{{inventory.name}}</a> 
</div> 

回答

0

我找到了解決辦法

$scope.selected = function(id) { 
     for(var i = 0; i < $scope.inventories.length; i++){ 
      if($scope.inventories[i].id == id){ 
       console.log(id); 
       var selectedInventory = Restangular.copy($scope.inventories[i]); 
       selectedInventory.customPUT({checked : true});     
      } 
     } 
    };