Strongberop与Emberjs [英] Strongloop with Emberjs

查看:130
本文介绍了Strongberop与Emberjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ember Data的REST适配器以以下格式从服务器接受JSON:

Ember Data's REST Adapter accepts the JSON from the server in this format:

从文档中可以看出: http://guides.emberjs.com/v1.10.0/models/the-rest-adapter/

{
  "post": {
    "id": 1,
    "title": "Node is not omakase",
    "comments": [1, 2, 3]
  },

  "comments": [{
    "id": 1,
    "body": "But is it _lightweight_ omakase?"
  },
  {
    "id": 2,
    "body": "I for one welcome our new omakase overlords"
  },
  {
    "id": 3,
    "body": "Put me on the fast track to a delicious dinner"
  }]
}

是否可以从strongloop回收这种JSON格式?

Is it possible to have this kind of JSON format back from strongloop?

推荐答案

远程方法不是最好的解决方案,因为它们是每个模型,因此不是DRY。

Remote methods are not the best solution because they are per model, and thus not DRY.

您可以使用 DS.RESTAdapter 与<$ c $,使Ember数据与Strongloop的环回API兼容c> DS.JSONSerializer 像这样:

// app/adapters/application.js

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  host: 'http://loopback-api-host',
  namespace: 'api',
  defaultSerializer: 'JSONSerializer'
});

http://emberjs.com/api/data/classes/DS.JSONSerializer.html

在Ember Data中,用于与后端数据存储进行通信的逻辑位于适配器中,Ember Data适配器有一些关于REST API应该如何看待的内置假设,如果您的后端约定与这些假设不同,Ember Data可以轻松更改其功能是通过交换或扩展默认适配器。

"In Ember Data, the logic for communicating with a backend data store lives in the Adapter. Ember Data's Adapter has some built-in assumptions of how a REST API should look. If your backend conventions differ from these assumptions Ember Data makes it easy to change its functionality by swapping out or extending the default Adapter."

http://guides.emberjs.com/v2.0.0/models/customizing-adapters/

类似问题:
使环回API Ember.js兼容

这篇关于Strongberop与Emberjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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