【问题标题】:how i can remove item from multiple array in angularjs我如何从angularjs中的多个数组中删除项目
【发布时间】:2016-11-16 22:09:08
【问题描述】:

我具有删除多个数组 angularjs 中的项目的功能。我使用像下面这样的工厂

app.factory("array_obj", function () {
       var currentUserIDs = {};
       currentUserIDs.data = [];
       currentUserIDs.city = [];
       return currentUserIDs;

       });

在控制器中有这样的功能

$scope.deleteItem = function (index) {
                        currentUserIDs.city.splice(index, 1);
                         setUserID(); //insert data in url realtime
                    }

这仅适用于像 city

这样的一个数组

我需要一个函数来删除 array_obj

中的任何项目

【问题讨论】:

    标签: angularjs multidimensional-array


    【解决方案1】:

    function simpleController($scope) {
        $scope.data = { 
           "results1": [ { "id": 1, "name": "Test" }, { "id": 2, "name": "Beispiel" }, { "id": 3, "name": "Sample" } ] ,
           
    
    "results2": [ { "id": 1, "name": "Test2" }, { "id": 2, "name": "Beispiel2" }, { "id": 3, "name": "Sample2" } ] 
    
    }
        ;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <html ng-app>
        
        <body ng-controller="simpleController">
          <div data-ng-repeat="results in data">
               <div data-ng-repeat="result in results">>
                 
                 {{result.name}}</br>
               </div> 
            </div> 
      
      </body>
    
    </html>

    玩得开心..!!!

    【讨论】:

      【解决方案2】:

      在您的控制器中:

      $scope.all_results = data.results1.concat(data.results2);
      

      在你看来

      <whatever ng-repeat="item in all_results">{{ item.id }} - {{ item.name }}</whatever>
      

      【讨论】:

        【解决方案3】:

        您可以在 HTML 中使用额外的 &lt;div&gt;ng-repeat 属性,在我的示例结果中是您的数据。

        <div>
            <div ng-repeat="result in results">
                <div ng-repeat="item in result">{{item.name}}</div>
            </div>
        </div>
        

        【讨论】:

          【解决方案4】:

          好的,这项工作......我有删除多个数组 angularjs 中的项目的功能。我使用像下面这样的工厂

          app.factory("array_obj", function () {
                 var currentUserIDs = {};
                 currentUserIDs.data = [];
                 currentUserIDs.city = [];
                 return currentUserIDs;
          
                 });
          

          在控制器中有这样的功能

          $scope.deleteItem = function (index) {
                                  currentUserIDs.city.splice(index, 1);
                                   setUserID(); //insert data in url realtime
                              }
          

          这仅适用于像 city

          这样的一个数组

          我需要一个函数来删除 array_obj 中的任何项目

          【讨论】:

            猜你喜欢
            • 2016-10-30
            • 1970-01-01
            • 1970-01-01
            • 2021-10-19
            • 2012-12-24
            • 1970-01-01
            • 1970-01-01
            • 2018-09-04
            • 1970-01-01
            相关资源
            最近更新 更多