2017-04-19 58 views
0

在代碼中,有ng-repeat,我必須更新由ng-repeat顯示的所有值的「frais」。此代碼只更新最後一個值。我該怎麼做才能更新所有內容?更新ng-repeat值angularJS和php

file.html

<ion-content class="padding" ng-controller="FactureAdminCtrl" ng-repeat = "selectedName in selected"> 

<ion-list ng-repeat = "selectedName in selected"> 
      <div class="item item-divider center-text" name="codeE" ng-model="selectedName.CodeEnvoiColis"> {{selectedName.CodeEnvoiColis}} </div> 

      <label class="item item-input"> 
      <input width="20%" type="text" placeholder="Frais" ng-model="selectedName.FraisFact" style="color:#BA1B1B;"></div> 
      </label> 
</ion-list> 

<a class="button button-info" href="#/factureAdmin" ng-click=updateFact(selectedName)> Submit </a> 

app.js

$scope.updateFact = function(selectedName){ 

      $http.post( 
       "http://localhost/deb/updatFact.php", 
       { 

       'FraisFact':$scope.selectedName.FraisFact, 
       'CodeEnvoiColis':$scope.selectedName.CodeEnvoiColis, 
       } 
      ).success(function(data){ 
       alert(data);         
      }); 
    } 

我該怎麼辦,請!

回答

1

首先不要把NG-重複這一行,

<ion-content class="padding" ng-controller="FactureAdminCtrl" ng-repeat = "selectedName in selected"> 

刪除它這個樣子,

<ion-content class="padding" ng-controller="FactureAdminCtrl"> 

然後,你必須充分陣列發送到updateFact功能,

<a class="button button-info" href="#/factureAdmin" ng-click=updateFact(selected)> Submit </a> 

因此,完整的數組將在這裏函數&你必須將它傳遞到後端&做任何你想要的東西&返回數據。

$scope.updateFact = function(selected){ 

      $http.post( 
       "http://localhost/deb/updatFact.php", 
       //you have to pass the array here 
      ).success(function(data){ 
       alert(data);         
      }); 
    } 
+0

謝謝,但我不明白你的意思是哪個數組! – SalamSalam

+0

'selected'是一個數組嗎?所以你必須發送這個數組到後端&進程 – DilumN

+0

這是選中的函數:$ rootScope.selected = []; $ rootScope.namesF3 = []; $ rootScope.exist = function(item){ return $ rootScope.selected.indexOf(item)> -1; } $ rootScope.toggleSelection = function(item){ var x = []; var idx = $ rootScope.selected.indexOf(item); if(idx> -1){rootScope.selected.splice(idx,1); } else { $ rootScope.selected.push(item); } } – SalamSalam