【问题标题】:Ember Serializer works for Mirage but not with real dataEmber 序列化程序适用于 Mirage 但不适用于真实数据
【发布时间】:2016-02-20 02:57:39
【问题描述】:

我是 Ember 的新手,正在尝试使用 beta 2.3.0 创建一个小型应用程序。

提供了国家和邮政编码,我正在尝试获取城市和邮政编码。 使用 Mirage 和自定义序列化程序(我使用与真实 json 相同的格式),我的代码可以完美运行。

但是,对于真正的 API,Promise 仍处于 Pending 状态。控制台没有错误。 并且我的序列化程序中的日志在使用实际服务时不显示,表明序列化程序没有执行。 以前有没有人遇到过类似的问题。请帮忙。

在我的控制器中,我发现记录为:

this.store.find('address', zipcode).then(
                function(address) {
                    console.log("Hello Got Address");
});

我的适配器/application.js:

export default DS.RESTAdapter.extend({
 host: 'http://real_url_here',

 pathForType: function(type) {
      return '';
}});

JSONAPISerialier 在 serializers/application.js 中被覆盖为:

export default DS.JSONAPISerializer.extend({

normalizeResponse(store, primaryModelClass, payload, id, requestType) {

.......... // Code goes here
}});

在我的 mirage/config.js 中,我返回了 2 个邮政编码的示例 json,最后我添加了:

this.passthrough('http://real_url_here/**');

为其他邮政编码调用真正的服务

【问题讨论】:

  • 请添加一些示例代码。

标签: json ember.js adapter serialization


【解决方案1】:

我终于得到了答案:)。

我不得不禁用开发中的海市蜃楼:

要在开发中禁用,

// config/environment.js
...
if (environment === 'development') {
      ENV['ember-cli-mirage'] = {
      enabled: false
}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多