加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular.js中的$resource关系[更新]

发布时间:2020-12-17 17:17:34 所属栏目:安全 来源:网络整理
导读:I’m trying to figure out the best way to write a model that relates to other models,such as an Order that has 1 or more OrderItems. 如何在加载订单时获取相应的OrderItem? angular .module('MyApp.services',['ngResource']) .factory('Order',fu

I’m trying to figure out the best way to write a model that relates to other models,such as an Order that has 1 or more OrderItems.

如何在加载订单时获取相应的OrderItem?

angular
    .module('MyApp.services',['ngResource'])
        .factory('Order',function($resource) {
            return $resource('/api/v1/Order/:orderId?format=json',{},{});
        });
        .factory('OrderItem',function($resource) {
            return $resource('/api/v1/OrderItem/:orderitemId?format=json',{});
        });

我在get order上尝试了一个回调函数来加载OrderItems,但是没有用.

有一个非常相似的问题,但它已经过时了:$resource relations in Angular.js

解决方法

您可以将该函数包装在另一个获取订单商品的位置吗?

myApp.factory('Order',function($resource) {
  var res = $resource('/api/Order/:orderId',{
    '_get': { method: 'GET' }
  });

  res.get = function(params,success,error) {
    return res._get(params,function(data) { 
      doOrderItemStuff();
      success(data);
    },error);
  }
  return res;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读