Jquery 使用splice()时出现AngularJS错误
我试图在angularjs中从scope和DB中删除一条记录,但出现了错误。虽然我的记录正在删除,但未在范围内删除,并显示错误 未捕获的TypeError:无法读取未定义的属性“charAt” 这是我的密码Jquery 使用splice()时出现AngularJS错误,jquery,angularjs,typeerror,Jquery,Angularjs,Typeerror,我试图在angularjs中从scope和DB中删除一条记录,但出现了错误。虽然我的记录正在删除,但未在范围内删除,并显示错误 未捕获的TypeError:无法读取未定义的属性“charAt” 这是我的密码 <a ng-click="deleteUser(user.id)">Delete</a> 您可以尝试在发布之前获取用户,然后 你能做以下事情吗 1.当您在init方法中第一次绑定数据时 var bindToGrid=function(){ $scope.user
<a ng-click="deleteUser(user.id)">Delete</a>
您可以尝试在发布之前获取用户,然后
你能做以下事情吗 1.当您在init方法中第一次绑定数据时
var bindToGrid=function(){
$scope.usersData=data;//from api
}
二,。删除时,您正在调用正确的api
$scope.deleteUser = function (uid) {
if(confirm("Are you sure to delete this?")){
$http.post("functions.php?type=deleteUser&uid="+uid).success(function(data){
$scope.users.splice(uid, 1);
});
}
};
三,。但是在成功之后,您必须再次调用init,如下所示
$scope.deleteUser = function (uid) {
if(confirm("Are you sure to delete this?")){
$http.post("functions.php?type=deleteUser&uid="+uid).success(function(data){
$scope.bindToGrid();
});
}
};
这将重新绑定到模型对象并反映更改。拼接的第一个参数应该是要删除的项的索引,而不是值谢谢:我只是在html中使用angularjs属性$index。
$scope.deleteUser = function (uid) {
if(confirm("Are you sure to delete this?")){
$http.post("functions.php?type=deleteUser&uid="+uid).success(function(data){
$scope.users.splice(uid, 1);
});
}
};
$scope.deleteUser = function (uid) {
if(confirm("Are you sure to delete this?")){
$http.post("functions.php?type=deleteUser&uid="+uid).success(function(data){
$scope.bindToGrid();
});
}
};