Angularjs 从阵列中删除不工作的项
这可能是一个非常简单且愚蠢的错误,但由于某些原因,我无法从使用Ajax调用创建的数组中删除项。当我尝试删除它时,会出现以下JS错误:Angularjs 从阵列中删除不工作的项,angularjs,Angularjs,这可能是一个非常简单且愚蠢的错误,但由于某些原因,我无法从使用Ajax调用创建的数组中删除项。当我尝试删除它时,会出现以下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-b5
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)
TypeError:未定义不是函数
在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)
打电话(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:174:190)
在https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:191:167
在h$get.h$eval时(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:111:121)
在h.$get.h.$apply(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:111:399)
在HTMLTableRowElement。(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js:191:149)
在HTMLTableRowElement.jQuery.event.dispatch(https://www.skykick.com/CMSScripts/jquery/jquery-core.js:3350:9)
在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>
最近
{{activity.Description}}
{{activity.Count}
{{activity.CustomerName}
{{activity.Date}
var app=angular.module('Skykick',['ngRoute']))
app.controller('MainCtrl',函数($scope,$http){
$scope.activities=新数组();
$scope.remove=功能(活动){
console.log(活动);
$scope.activities.remove(活动);
}
$http({
方法:“GET”,
网址:'https://www.skykick.com/WebApi/activity/recent/all'
})
.成功(功能(数据、状态){
$scope.activities=data.result.Activity;
})
.错误(功能(数据、状态){
控制台日志(数据);
警报(“错误”);
});
});
JavaScript没有.remove()属性,因此您必须对其进行重构,使其更适合JavaScript。如果activities是一个数组,那么可以使用.slice()。JavaScript没有内置的.remove()属性。噢,哇,idk我当时在想什么……我刚刚给出了答案。很高兴我能帮忙。