【问题标题】:Ember not detecting all attributes from server responseEmber 未从服务器响应中检测到所有属性
【发布时间】:2016-10-21 12:54:42
【问题描述】:

编辑:Ember 1.7.1ember-data 1.0.0-beta12

来自服务器的响应似乎正确,但 ember 似乎没有将响应正确加载到数据中。以下是findQuery()feedstories 的回复:

创建记录后,服务器发送以下响应。这似乎是正确的,因为它是一个单独的记录创建。

Ember 会加载 story_type 帖子,但您可以看到其他属性,例如 global_id(已在序列化程序中设置为主键)尚未加载。嵌入的故事属性也有同样的问题,其中一些信息是正确的(正文、标题等),但不会加载所有其他属性。它们被设置为undefined

我认为我在客户端序列化数据的方式可能有问题。但由于一些信息正在加载,我不太确定。有什么想法吗?

下面是适配器和序列化器:

App.FeedstorySerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    primaryKey: 'global_id',
    attrs: {
        pin: {embedded: 'always' },
        story: {embedded: 'always'},
    },
    serializeIntoHash: function(hash, type, record, options){
        // Removed the root element from the request payload.
        // If not completed, causes issue when getting data from
        // the bundle object on the server.
        Ember.merge(hash, this.serialize(record, options));
    },
});


App.FeedstoryAdapter = App.ApplicationAdapter.extend({
    buildURL: function(type, id, record){
        this._super();
        url = '/' + this.namespace + '/feedstories/'
        return url
    }
});

【问题讨论】:

  • 愚蠢的问题:所有这些属性都在你的模型中定义了吗?
  • @ChrisPeters 是的,似乎是,我没有收到任何警告,并且检查过它们都是。当 findQuery 执行提要故事时,所有数据都会正确加载。当我创建一个新故事时,什么都没有发生,我希望它能够在其他故事之上展示新故事。
  • @ChrisParry 新的会显示在底部吗?

标签: javascript rest ember.js ember-data


【解决方案1】:

querysingle 响应中,您的 json 中缺少根 feedstory 键。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 2017-09-11
    • 1970-01-01
    相关资源
    最近更新 更多