删除功能不适用于angularJS [英] Delete function not working with angularJS

查看:44
本文介绍了删除功能不适用于angularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的js代码:

camListApp.controller("Hello", function($scope, $http, $uibModal){

    $scope.del=function(data){

        var result=confirm('are you sure?');
        if(result==true){
        var index=getSelectedIndex(data);
        $scope.records.splice(index, 1);
        }
        };
        function getSelectedIndex(data) {
        for (var i =0; i<$scope.records.length; i++)
        if($scope.records[i].data==data)
        return i;
        return -1;
        }

HTML代码:

  <td><button class="btn" ng-click="del(record.filename)">Delete</button></td>

我的json数据:

[{"cameraid":"000000001","timestamp":"2016-07-09 10:06","filename":"c037731fc2256177ba29c7893caacf04","locationid":"Bedok01"}   
{"cameraid":"000000003","timestamp":"2016-07-13 11:35","filename":"4fd2413d30073b4b6a5cacbb8b7c1965","locationid":"Bedok01"} 
{"cameraid":"000000003","timestamp":"2016-07-13 14:41","filename":"6b6b62948eb679efeb650d609c85b7aa","locationid":"Bedok01"}

我该如何在angularjs上执行删除功能,并单击该按钮,同时mongodb也会删除数据.有人可以帮忙吗?

How can i do a delete function on angularjs and when the button is clicked and at the same time mongodb also remove the data. Anybody can help?

推荐答案

进行http调用以从数据库中删除,然后使用如下所示的splice从列表中删除对象

make http call to delete from db and then remove the object from list using splice as below

<td><button class="btn" ng-click="del(record)">Delete</button></td>

$scope.del = function(record) {
var index = $scope.records.indexOf(record);
$scope.records.splice(index , 1);
    $scope.list();
};

这篇关于删除功能不适用于angularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆