JSONAPIAdapter - 使用camel case而不是dasherized case

时间:2016-03-10 05:58:18

标签: ember-data

在序列化JsonApi模型时,是否有一种快速简便的方法来使用z[:]?默认情况下,对于网址和字段名称都使用camel case

1 个答案:

答案 0 :(得分:2)

请查看EmberJS guides以获取与user-profile相关的适配器匹配user_profile的示例:

export default DS.JSONAPIAdapter.extend({
  pathForType: function(type) {
      return Ember.String.underscore(type);
  }
});
  

person的请求现在将定位/person/1user-profile的请求现在将定位/user_profile/1

如果您需要序列化属性,而不仅仅是模型名称,您可以在同一位置找到该主题的相关部分,直接链接here

由于上面的示例使用了Ember.String.underscore(),因此我附加了一个非常有用的字符串助手的链接,默认情况下,Ember提供了Ember.String API