PhoneGap中文网

 找回密码
 立即注册
查看: 16789|回复: 1
打印 上一主题 下一主题

使用splice()批量删除选中的选项时遇到的问题

[复制链接]

3

主题

11

帖子

157

积分

注册会员

Rank: 2

积分
157
跳转到指定楼层
楼主
发表于 2016-1-26 15:00:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
for (var i = 0; i < $scope.portalListData.length; i++) {
    if ($scope.portalListData[i].checked) { //选中的
        $scope.portalListData.splice($scope.portalListData.indexOf($scope.portalListData[i]), 1);
    } else {
    }
}
如上 删除会出现问题,比如选中八个只会删除四个,选中四个删除两个,此处一个解决方法就是 在删除掉本条之后,即   $scope.portalListData.splice($scope.portalListData.indexOf($scope.portalListData[i]), 1);这一句之后加一句 i-- 就可以解决了!
for (var i = 0; i < $scope.portalListData.length; i++) {
    if ($scope.portalListData[i].checked) { //选中的
        $scope.portalListData.splice($scope.portalListData.indexOf($scope.portalListData[i]), 1);        i--;
    } else {
    }
}
回复

使用道具 举报

493

主题

2035

帖子

6894

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
6894
沙发
发表于 2016-1-27 10:21:51 | 只看该作者
这样的话  你循环过滤一下就可以了,不需要再一个一个删除了。

循环过滤的时候,没有选中的放在一个数组/对象,选中的过滤掉

然后在把新数组的值给以前的对象/数组
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

ionic4视频教程

Archiver|手机版|小黑屋| PhoneGap中文网 ( 京ICP备13027796号-1 )  

GMT+8, 2024-4-20 23:58 , Processed in 0.043308 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表