使用php更新ng-repeat值angularJS

时间:2017-04-19 16:35:52

标签: php angularjs ionic-framework

在代码中,有重复,我必须更新" frais" ng-repeat显示的所有值的值。此代码仅更新最后一个值。我该如何更新所有内容呢?

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 个答案:

答案 0 :(得分:1)

首先,不要将ng-repeat放到这一行,

<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>

所以完整的数组将在函数&amp;你必须把它传递到后端和做任何你想做的事情&amp;返回数据。

$scope.updateFact = function(selected){ 

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