每次迭代时ng重复ng-change函数时影响数组

时间:2018-03-01 06:51:23

标签: javascript html angularjs

我使用CarDetailsng-init="loadcat()"类别中获取ng-change="GetProduct(cap.categoryid)"中的动态数据获取类别数组数据。 同样在ProductsArray ng-change="GetSubCategory(cap.categoryid,cap.productname)"中获取productname

中的动态数据

但问题是,当我再添加一行时,再次选择类别subcatids也会更改前一行。

对于每次迭代,如何在 ng-repeat 中的每个选择类别上获得ProductsArray。 kinldy帮助我 谢谢你提前



ProductsArray

var app = angular.module("myapp", []);

app.controller("ctrl", function($scope, $http, jsonFilter) {

  $scope.loadcat = function() {
    $http.get("cat_load.php")

      .success(function(data, status, headers, config) {
        $scope.CategoryArray = data;
      });
  }

  $scope.GetProduct = function(categoryid) {
    $http.post("product_load.php", {
        'cat_id': categoryid
      })

      .success(function(data, status, headers, config) {
        $scope.ProductsArray = data;
      });
  }

  $scope.GetSubCategory = function(categoryid, productname) {
    $http.post("subcat_load.php", {
        'cat_id': categoryid,
        'productname': productname
      })
      .success(function(data, status, headers, config) {
        $scope.subcatids = data;
      });
  }


  /**********to add remove row start here **********/

  $scope.remove_Row = function(name) {
    var index = -1;
    var comArr = eval($scope.data);
    for (var i = 0; i < comArr.length; i++) {
      if (comArr[i].name == name) {

        index = i;
        break;
      }
    }
    if (index == -1) {
      //alert( "Something gone wrong" );
    }
    $scope.data.splice(index, 1);
  };

  // dynamic row creation 
  $scope.data = [{}];
  $scope.addFormField = function() {
    //alert($scope.data);
    $scope.data.push({});
  }

  /**********to add remove row End here **********/
});
&#13;
&#13;
&#13;

0 个答案:

没有答案