我很习惯正常的MVC服务器端编码,现在我正在尝试学习角度。我想创建一个用户界面,人们可以在其中添加团队参加他们登录的竞赛。要从我正在使用的列表中删除团队:
angular.module('Xtho.InschrijfController', [])
.controller("InschrCtrl", [
'$scope', '$http', function ($scope, $http) {
$scope.model = {};
$scope.wedstrijden = {};
$scope.states = {
};
$scope.new = {
ploeg: {}
};
$http.get('/inschrijvingen/IndexVM').then(function (data) {
$scope.model = data;
});
$scope.Vploeg = function (id, index) {
$http.post('/inschrijvingen/PloegVerwijderen', { id: id }).then(function (response) {
$scope.model.splice(index, 1);
});
};
}
]);
,这是在视图中:
<p>{{ploegen.PloegNaam}} <a href="#" ng-click="Vploeg(ploegen.PloegID, $index)"><span class="fa fa-trash-o" aria-hidden="true"></span></a></p>
代码有效!但是,由于记录已从数据库中删除,因此它们仍位于页面上显示的列表中。控制台提供以下错误:&#34; n.model.splice不是函数&#34;,解决此问题的最佳方法是什么?
答案 0 :(得分:0)
像这样的东西。
angular.module('Xtho.InschrijfController', [])
.controller("InschrCtrl", [
'$scope', '$http', function ($scope, $http) {
$scope.model = {};
$scope.wedstrijden = {};
$scope.states = {
};
$scope.new = {
ploeg: {}
};
$scope.load = function(){
$http.get('/inschrijvingen/IndexVM').then(function (data) {
$scope.model = data;
});
};
$scope.load();
$scope.Vploeg = function (id, index) {
$http.post('/inschrijvingen/PloegVerwijderen', { id: id
}).then(function (response) {
//$scope.model.splice(index, 1);
$scope.load();
});
};
}
]);
答案 1 :(得分:0)
$scope.model=[]//list
$scope.model={}//javascript object
使用$ scope.model = []
答案 2 :(得分:0)
在此行中,您尝试删除$scope.model.splice(index, 1);
变量的一个元素:
splice()
我们只能将$scope.model
用于数组,但看起来$scope.model = {};
不是数组,它在代码中声明为对象:
$scope.model
当您尝试从中拼接元素时,我真的不知道$scope.Vploeg = function (id, index) {
$scope.idForRemove = id;
$http.post('/inschrijvingen/PloegVerwijderen', { id: id })
.then(function (response) {
delete $scope.model[$scope.idForRemove];
});
}
}
的类型。如果它是一个对象,则最好通过id删除元素:
[Fault] exception, information=Error: Error #3001: File or directory access denied.
in flash.filesystem::FileStream/open