更新ng-repeat输入值

时间:2017-04-30 17:21:04

标签: php angularjs ionic-framework

在代码中,有ng-repeat,我必须更新ng-repeat显示的所有值的“frais”。我怎么能这样做,我正在使用angularJS和PHP

file.html

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

<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);                                
   });  

} 

updateFact.php

 <?php   

      $CodeEnvoiColis = mysqli_real_escape_string($connect, $data->CodeEnvoiColis);  
      $FraisFact = mysqli_real_escape_string($connect, $data->FraisFact);  

      $query = "UPDATE colis SET FraisFact='$FraisFact' WHERE CodeEnvoiColis='$CodeEnvoiColis'" ;

 ?>

我该怎么办!

1 个答案:

答案 0 :(得分:0)

这不好,但你可以试试这个

HTML

  <input ng-model="updateValue"/>
    <button ng-click="update(updateValue)>Update</button>

JS

$scope.selected=[//data of you]
var x = [];
   for(var i= 0;i<$scope.selected.length;i++){
          x.push($scope.selected[i].CodeEnvoiColis)
        }
   $scope.updateFact = function(value){
       $http.post({
         method:'POST',
         url :'update.php',
        data: {
        CodeEnvoiColis1 : x[0],
        CodeEnvoiColis1 :x[1],
          ...
        FraisFact      :value
    },  transformRequest:function(obj) {
            var str=[];
            for(var p in obj){
    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]))
                                    }
                    return str.join("&");
                                },
        headers : {'Content-Type':'application/x-www-form-urlencoded'}
    }).then(function(data){
         alert(data)
    })
    } 

在php中

 $value = isset($_POST['value']) ? trim($_POST['value']) : '';
    $CodeEnvoiColis1 =  isset($_POST['CodeEnvoiColis1 ']) ? trim($_POST['CodeEnvoiColis1 ']) : '';
...
    UPDATE colis SET FraisFact ='$value' WHERE  CodeEnvoiColis IN ('CodeEnvoiColis1','CodeEnvoiColis2',...  )

或上面的代码不起作用

  UPDATE colis SET FraisFact ='$value' WHERE  CodeEnvoiColis ='$CodeEnvoiColis1';
   UPDATE colis SET FraisFact ='$value' WHERE  CodeEnvoiColis ='$CodeEnvoiColis2';
 ....