【发布时间】:2014-02-19 22:49:35
【问题描述】:
基本上我有点不确定我应该如何创建/管理我的资源。我正在考虑将资源作为(MVC)背景中的模型。例如,这是我的工厂:
angular.module('resources.question', ['ngResource'])
.factory('Question', function ($resource) {
return $resource('/:questionId', {questionId: '@id'}, {
postTest: {method: 'POST', url: '/create/:pageId/:questionId', params: {questionId: 0}},
search: {method: 'GET', url: '/search/:query', params: {query: ''}, isArray: true},
edit: {method: 'GET', url: '/edit/:pageQuestionId'},
delete: {method: 'GET', url: '/delete/:pageQuestionId'},
addExisting: {method: 'GET', url: '/addtopage/:pageId/:questionId'}
});
});
我注意到我有一些重复的任务,比如插入数据。例如:
var newQuestion = Question.addExisting({
pageId: data.pageId,
questionId: data.questionId,
id: $scope.data.search.question.id
});
//update object from database
$rootScope.survey.pages[data.pageIndex].questions.splice(data.questionIndex, 0, newQuestion); //insert the data
所以基本上我不确定如何处理类似的情况。我的工厂是否需要以某种方式扩展以处理此类数据操作,或者我是否需要为此类任务创建另一个工厂。还是只是我想多了?
【问题讨论】:
标签: angularjs