从数组角度删除项目不起作用

时间:2014-06-11 19:24:30

标签: angularjs

这可能是一个非常简单和愚蠢的错误,但由于某种原因,我无法从我使用Ajax调用创建的Array中删除项目。当我尝试删除它时,我得到了这个JS错误:

TypeError: undefined is not a function
    at h.$scope.remove (https://www.skykick.com/cmsctx/pv/mhintzke/culture/en-US/wg/725a2fa0-45ad-4…d7912fdf1/-/cms/getdoc/468aee97-0186-4241-b599-22e97438dcfa/pv.aspx:190:31)
    at bb.functionCall (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:174:190)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:191:167
    at h.$get.h.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:111:121)
    at h.$get.h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:111:399)
    at HTMLTableRowElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:191:149)
    at HTMLTableRowElement.jQuery.event.dispatch (https://www.skykick.com/CMSScripts/jquery/jquery-core.js:3350:9)
    at HTMLTableRowElement.jQuery.event.add.elemData.handle.eventHandle (https://www.skykick.com/CMSScripts/jquery/jquery-core.js:2959:45)

以下是导致它的代码

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="CMSApp.CMSWebParts.SkyKick.PartnerPortalV2.Web_Planner.Test" %>

<div ng-app="Skykick" ng-controller="MainCtrl">
    <div class="dashSection">
    <table id="tActivities" class="activityTable">
        <caption>Recently</caption>
        <thead>
            <tr>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody id="tbActivities">
            <tr ng-repeat="activity in activities" ng-click="remove(activity)">
                <td>{{ activity.Description }}</td>
                <td>{{ activity.Count }}</td>
                <td>{{ activity.CustomerName }}</td>
                <td>{{ activity.Date }}</td>
            </tr>
        </tbody>
    </table>
</div>      
</div>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-route.min.js"></script>
<script type="text/javascript">
    var app = angular.module('Skykick', ['ngRoute'])

        app.controller('MainCtrl', function ($scope, $http) {

        $scope.activities = new Array();

        $scope.remove = function (activity) {
            console.log(activity);
            $scope.activities.remove(activity);
        }



        $http({
            method: 'GET',
            url: 'https://www.skykick.com/WebApi/activity/recent/all'
        })
        .success(function (data, status) {
            $scope.activities = data.result.Activity;
        })
        .error(function (data, status) {
            console.log(data);
            alert("error");
        });
    });
</script>

1 个答案:

答案 0 :(得分:1)

JavaScript没有.remove()属性,所以你必须重构它才能成为更多的JavaScript。如果活动是数组,则可以使用.slice()。