从getList访问原始JSON(un-restangularized)

时间:2013-08-20 14:07:41

标签: angularjs restangular

有趣的是(至少对新手来说)如果你从DJANGO(以及可能的其他后端)返回整个列表,回复可能会改变。在我的情况下,DJANGO Rest Framework在返回分页后返回了一个数组,要求我重写此功能。


这似乎是这样做的:

RestangularProvider.setResponseExtractor(function(response) {
  var newResponse = response;
  if (angular.isArray(response)) {
    angular.forEach(newResponse, function(value, key) {
      newResponse[key].originalElement = angular.copy(value);
    });
  } else {
    newResponse.originalElement = angular.copy(response);
  }

  return newResponse;
});

来自:

https://github.com/mgonto/restangular#how-can-i-access-the-unrestangularized-element-as-well-as-the-restangularized-one


我希望能够删除从restangular添加的其他方法,以便我可以使用angular.equals或类似的方法将简单的JSON对象与restangularized版本进行比较。

工作流程

> 1: get array of objects from server 
> 2: allow the user to add a new item to the list (via form) 
> 3: only enable the save button IF this exact object is not already in the list

1 个答案:

答案 0 :(得分:0)

在原帖中回答并更新。

相关问题