【问题标题】:update specific value of ng-repeat with angularJS and PHP [duplicate]使用 angularJS 和 PHP 更新 ng-repeat 的特定值 [重复]
【发布时间】:2017-05-11 21:45:53
【问题描述】:

我想使用 PHP 和 AngularJS 更新“$code”的“Num”;但它只更新最后一个 ng-repeat 值,而不是点击的那个。

html 文件:

  <ion-list ng-repeat="x in names| filter: {Num: thisX}:true">
          <ion-item> 
          <div class="item item-divider center-text" ng-model='x.Code'> {{x.Code}} </div>
  <ion-item>
  <b>Date</b> <span class="item-note">  {{x.Date}} </span>
  </ion-item>
         <a class="button button-info" ng-click="update()">Update</a>
        ...

app.js

$scope.update = function(){ 

                 $http.post("http://localhost/deb/update.php",
                  {
                    'Code' :$scope.x.Code,                 
                  }
                  ).success(function(data){
                    alert(data);  
                 $scope.thisX = $state.params.Num; 
                  });  
           } 

更新.php

$data = json_decode(file_get_contents("php://input"));  
     if(count($data) > 0)  
 {   
      $Code = mysqli_real_escape_string($connect, $data->Code);                 
    $query = "UPDATE sale
    SET 
    Num=Null WHERE Code='$Code'"; 
      if(mysqli_query($connect, $query))  
      {  
           echo "modification réussie ...";  
      }  
      else  
      {  
           echo 'Error';  
      }  
  }

【问题讨论】:

    标签: php angularjs ionic-framework


    【解决方案1】:

    x 作为参数传递给函数

    <a class="button button-info" ng-click="update(x)">Update</a>
    

    使用该参数分配Code

    $scope.update = function(x){ 
    
                     $http.post("http://localhost/deb/update.php",
                      {
                        'Code' : x.Code,                 
                      }
                      ).success(function(data){
                        alert(data);  
                     $scope.thisX = $state.params.Num; 
                      });  
     } 
    

    【讨论】:

    • 谢谢,这正是我需要的,它解决了我的问题,非常感谢
    • @SalamSalam 没问题,如果这有帮助,请务必点赞并标记为正确答案:D
    • 我当然会,我只是在等待延迟(12 分钟)。非常感谢
    猜你喜欢
    • 1970-01-01
    • 2014-12-29
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    相关资源
    最近更新 更多