【问题标题】:ember-data 1.0 json structureember-data 1.0 json结构
【发布时间】:2013-09-03 05:33:25
【问题描述】:

随着对 ember-data (see here) 的所有更改,我正在努力确定 json 格式是否也发生了更改。

例如,如果我有以下型号

App.Contact  = DS.Model.extend({
    contactGroupGUID: DS.attr('string'),
    email: DS.attr('string'),
    firstName: DS.attr('string'),
    id: DS.attr('string'),
    lastName: DS.attr('string'),
    notes: DS.attr('string')
})    

contactGroupGUID、firstName 和 lastName 的 json 字段名称是什么?

还是 first_name 和 last_name 吗? (我从来不知道contactGroupGUID应该是什么;))

谢谢

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    Ember Data 1.0.beta.1 不会对 JSON 有效负载中的键做任何事情。默认情况下,带下划线的属性不再是驼峰式。此外,相关模型 ID 引用不再具有 _id_ids 后缀。因此,如果您在 0.13 中通过了以下内容:

    { post: {
      { title: "The future is now",
        extended_title: "The future is now: be prepared",
        author_id: 17,
        comment_ids: [7165, 8937, 9384]
      }
    }
    

    1.0.beta.1 期待:

    { post: {
      { title: "The future is now",
        extendedTitle: "The future is now: be prepared",
        author: 17,
        comment: [7165, 8937, 9384]
      }
    }
    

    可以配置密钥转换 (c.f. https://github.com/emberjs/data/blob/master/TRANSITION.md#rest-adapter-and-serializer-configuration) 并且可能会有更多配置选项,例如将来在哪里寻找相关模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      • 1970-01-01
      • 2014-08-23
      • 1970-01-01
      相关资源
      最近更新 更多