我正在使用angularfire来管理一些在线课程,我的课程每个都有很多讲座。我在课程中嵌套了讲座。我有一个工厂,它成功地允许CRUD操作我的课程但是对于我的讲座,我可以做所有 除 删除。有人可以告诉我删除操作有什么问题吗?非常感谢!
课程工厂:
angular.module('rutileApp')
.factory('Course', function ($firebaseArray, $firebaseObject, Ref) {
var courses = $firebaseArray(Ref.child('courses'));
var Course = {
all: courses,
create: function (course) {
return courses.$add(course);
},
get: function(courseId) {
return $firebaseObject(Ref.child('courses').child(courseId));
},
delete: function(course) {
return courses.$remove(course);
}
};
return Course;
});
讲座工厂:
angular.module('rutileApp')
.factory('Lecture', function ($firebaseArray, $firebaseObject, Ref) {
var Lecture = {
create: function (courseId, lecture) {
return $firebaseArray(Ref.child('courses').child(courseId)
.child('lectures')).$add(lecture);
},
get: function(courseId, lectureId) {
return $firebaseObject(Ref.child('courses')
.child(courseId).child('lectures').child(lectureId));
},
fromCourse: function(courseId) {
return $firebaseArray(Ref.child('courses')
.child(courseId).child('lectures'));
},
delete: function(courseId,lecture) {
return $firebaseArray(Ref.child('courses').child(courseId)
.child('lectures')).$remove(lecture);
}
};
return Lecture;
});
课程控制器:
$scope.deleteCourse = function (course) {
Course.delete(course);
};
课程控制器:
$scope.deleteLecture = function (courseId, lecture) {
Lecture.delete(courseId, lecture);
};
课程观点:
<table class="table table-striped">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="course in courses">
<td>
<button class="btn btn-primary"
ng-really-click="deleteCourse(course)"
ng-really-message="Are you sure?">
Delete
</button>
</td>
</tr>
</tbody>
</table>
课程视图:
<table class="table table-striped">
<thead>
<th></th>
</thead>
<tbody>
<tr ng-repeat="lecture in lectures">
<td>
<button class="btn btn-primary"
ng-really-click="deleteLecture(course.$id, lecture)"
ng-really-message="Are you sure?">
Delete
</button>
</td>
</tr>
</tbody>
</table>
如果我执行deleteLecture(课程。$ id,讲座。$ id),也会发生这种情况。
答案 0 :(得分:1)
尝试将其从delete重命名为remove,因为delete可以是某些javascript语言中的保留关键字。
答案 1 :(得分:0)
我想我得到了它。无论出于何种原因,我可以使用上面的删除课程,但对于任何嵌套我需要在视图中调用$ remove:
<tr ng-repeat="(id, lecture) in lectures">
<button class="btn btn-primary"
ng-really-click="lectures.$remove(lecture)"
ng-really-message="Are you sure?">
Delete
</button>
</td>
</tr>
剩下的问题是$ remove似乎不适用于任何嵌套的东西。如果我使用firebase来提取讲座的嵌套属性,我就不能使用$ remove。
<div ng-repeat="(id, lecture) in lectures">
<div ng-repeat="(id, questions) in lecture.questions">
<button class="btn btn-primary"
ng-really-click="lectures.$remove(question)"
ng-really-message="Are you sure?">
Delete
</button>
</div>
</div>
所以讲座。$ remove不起作用,处理它的正确方法是什么?