search

Home  >  Q&A  >  body text

angular.js - angular js点击按钮隐藏选中元素

如何点击按钮就删除选中元素?
<p class="Shopping_car" ng-app="myApp" ng-controller="myCon">

    <p class="headerW">
        <p class="header">
            购物车(2)
            <span class="trash_can" ng-click="remove($index)"></span>
            <br clear="all"/>
        </p>
    </p>
    <p class="mainbody">
        <ul>
            <li class="product_li" ng-class="{on:x.onSw}" ng-hide="x.li_hide" ng-repeat="x in products_mes">
                <p class="li_center">
                    <p class="select_btn" ng-click="toggleC($index)"></p>
                    <p class="goods_part">
                        <p class="leftbox">
                            <img src="{{x.products_img}}" width="100%" height="100%"/>
                        </p>
                        <p class="rightbox">
                            <p class="goods_content">{{x.content}}</p>
                            <p class="price_area">
                                <span class="new_money">{{x.newMoney}}</span>
                                <span class="old_money">{{x.oldMoney}}</span>
                                <span class="conter">
                                    <span class="remove_btn">-</span><input type="number" class="" value="1"/><span class="add_btn">+</span>
                                    <br clear="all"/>
                                    
                                </span>
                            </p>
                        </p>
                    </p>
                    <br clear="all"/>
                </p>
            </li>
            
            <li class="lost" ng-hide="sw">
                <p class="li_center">
                    <p class="select_btn"></p>
                    <p class="lose">失效</p>
                    <p class="goods_part">
                        <p class="leftbox">
                            <img src="img/product.png" width="100%" height="100%"/>
                        </p>
                        <p class="rightbox">
                            <p class="goods_content">娇韵诗清透润白柔肤水清爽型200ml</p>
                            <p class="price_area">
                                <span class="new_money">¥390.00</span>
                                <span class="old_money">¥420.00</span>
                                <span class="conter">
                                    <span class="remove_btn">-</span><input type="number" class="" value="1"/><span class="add_btn">+</span>
                                    <br clear="all"/>
                                    
                                </span>
                            </p>
                        </p>
                    </p>
                    <br clear="all"/>
                </p>
            </li>
          <script>
var app=angular.module("myApp",[]);
app.controller("myCon",function($scope){
    
        $scope.sw=false;
        $scope.disappear=function(){
            
                $scope.sw=true;
            
            };
        
        $scope.products_mes=[
        
        {
                
                onSw:false,
                content:"娇韵诗清透润白柔肤水清爽型200ml",
                newMoney:"¥390.00",
                oldMoney:"¥420.00",
                products_img:"img/product.png"
            
        },
        {
                
                onSw:false,
                content:"娇韵诗清透润白柔肤水清爽型100ml",
                newMoney:"¥390.00",
                oldMoney:"¥420.00",
                products_img:"img/product.png"
            
        }
        ];
        $scope.products_mes.onSw=false;
        $scope.toggleC=function($index){
                
                
                $scope.products_mes[$index].onSw=!$scope.products_mes[$index].onSw;
                var index = $scope.products_mes.indexOf($index);
                if($scope.products_mes[$index].onSw){
                    
                        
                    
                    }
            };
            
        $scope.delProds =[];
        
    
    
    });

</script>
点击.trash_can按钮隐藏选中的li标签

我想大声告诉你我想大声告诉你2744 days ago752

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 17:14:53

    Create an empty array to store the index of the data you need to delete, such as delProds

    Add ng-click to your checkbox
    When triggered, push the index of this product to the delProds array when it is judged to be true
    When it is false, delete it from delProds

    Then when you click the delete button, just delete all the data with the corresponding serial number

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-15 17:14:53

    Use splice(), such as products_mes.splice(subscript, 1) to delete an item in the array

    reply
    0
  • 某草草

    某草草2017-05-15 17:14:53

    $scope.remove = function(idx) {
        $scope.products_mes.splice(idx, 1);
    }

    reply
    0
  • 迷茫

    迷茫2017-05-15 17:14:53

    var index = products_mes.indexOf(data);
    products_mes.splice(index,1);
    data: for the selected object

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 17:14:53

    splice

    reply
    0
  • Cancelreply