在Angular.js $资源的关系[更新] [英] $resource relations in Angular.js [updated]

查看:95
本文介绍了在Angular.js $资源的关系[更新]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出最佳的方式来写,涉及到其他车型,比如有1个或更多的OrderItems订单的模式。

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.

我怎样才能得到相应的OrderItems当加载顺序?

How can I get respective OrderItems when a Order is loaded?

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', {}, {});
        });

我试着让以加载的OrderItems一个回调函数,但没有奏效。

I tried a callback function on get Order to load OrderItems, but didn't work.

有一个非常类似的问题,但它已经过时了:在Angular.js $资源关系

there is a very similar question, but it is obsolete: $resource relations in Angular.js

推荐答案

您可以在另一种获取订单商品包装的功能?

You could wrap the function in another that gets order items?

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;
}

这篇关于在Angular.js $资源的关系[更新]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆