美文网首页
数组删除

数组删除

作者: sunflower_07 | 来源:发表于2017-08-02 17:42 被阅读0次
            <!DOCTYPE html>
            <html ng-app="app1">
            <head>
                <title>splice</title>
            </head>
            <body >
            <div ng-controller="ctr">
                <div ng-repeat="item in obj">
                    <p><span>{{item.title}}</span><span>{{item.content}}</span>&nbsp;&nbsp;&nbsp;<span ng-click="del(item)">X</span></p>
                </div>
            </div>
            <script src="https://cdn.bootcss.com/angular.js/1.2.0/angular.js"></script>
            <script type="text/javascript">
                var app=angular.module("app1",[])
                app.controller("ctr",function($scope){
                    $scope.obj=[
                        {"title":"1111","content":"one"},
                        {"title":"2222","content":"two"},
                        {"title":"3333","content":"three"}
                    ];
                    $scope.del=function(item){
                        for(var i=0;i<$scope.obj.length;i++){
                            if($scope.obj[i]==item){
                                $scope.obj.splice(i,1);
                            }
                        }
                            
                        }                   
                })
            </script>
            </body>
            </html>

    相关文章

      网友评论

          本文标题:数组删除

          本文链接:https://www.haomeiwen.com/subject/jdlylxtx.html