angular.js - 请教在angular里从多维对象数组里删除某个对象数组的问题
给我你的怀抱
给我你的怀抱 2017-05-15 16:59:30
[AngularJS讨论组]

评论展示是ng-repeat,comment in comments。
有删除评论功能,ng-click之后,把comment传到删除函数里,然后从comments里把这个comment删掉,这个删除的语句应该怎么写呢?
谢谢!

给我你的怀抱
给我你的怀抱

全部回复(2)
大家讲道理
<p ng-repeat='comment in comments' ng-click='del($index,comments)'>{{comment}}</p>

$scope.delete=function(key,arr){
   arr.splice(key,1);
}
怪我咯

html

<p ng-repeat='comment in comments' ng-click='delete($index)'>{{comment}}</p>

js

app.controller('myCtrl', function($scope) {
    $scope.comments=[1,2,3,4]
    $scope.delete=function(i){
        $scope.comments.splice(i,1)
    }
})
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号