gpt4 book ai didi

javascript - 数据从数据库中删除成功,但未刷新 AngularJS 中的当前页面

转载 作者:行者123 更新时间:2023-12-03 09:42:24 25 4
gpt4 key购买 nike

我尝试了几次删除数据,它成功删除了数据,但没有显示更新的学生完整列表......

手动刷新网页后,它会显示更新的学生列表,请帮助我。

  
X.controller('StudentController', ['$scope', 'Student', 'Department', '$routeParams','$location', function ($scope, Student, Department, $routeParams,$location) {
$scope.v = 'test value';

$scope.profileid = $routeParams.Id;
console.log($scope.profileid);
////////////////RETRIVE ALL DATA FROM DB///////////////
function init() {
/////RETRIVE DATA FOR STUDENT/////////

$scope.student = { Name: '', Phone: '', Class_id: '', Department_id: '' };
$scope.students = [];
Student.get(function (response) {
console.log("List of Student");
$scope.students = response.Data;
console.log($scope.students);

});

///////RETRIVE DATA FOR DEPARTMENT////////////////////
$scope.depts = [];
Department.get(function (response) {
console.log("List of Dept");
$scope.depts = response.DeptData;
console.log($scope.depts);
});

};
////////////RETRIVE SPECIFIC DATA INTO DB/////////////
Student.get({ Id: $scope.profileid }, function (response) {
console.log("SPECIFIC DATA");
$scope.student = response.Data;
console.log($scope.students);

});
/////////////////////////////DELETE//////////////////
$scope.Stddelete = function (profileId) {
Student.delete({ Id: profileId });
console.log("DELETE");
init();
};

init();



}
]);

最佳答案

要更新 DOM,您需要从数组中拼接对象。

$scope.students.splice($index,1);

示例:

$scope.Stddelete = function (profileId,index) {
Student.delete({ Id: profileId });
$scope.students.splice(index,1);
console.log("DELETE");
init();
};

关于javascript - 数据从数据库中删除成功,但未刷新 AngularJS 中的当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31144482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com