1

Ember.Objectを使用して、ember-dataなしでemberjsを使用する予定です。バックエンドでレールを使用しています。json api レールが提供するアンダースコアを使用しています。エンバーエンドでキャメルケースに変更したいと考えています。効果的に行う方法は?ありがとう!

4

1 に答える 1

2

これを行うには2つの方法があると思います。key最初のものは、修飾子を使用して、AMS によってレンダリングされた json を変更することです。

If you would like the key in the outputted JSON to be different from its name in     ActiveRecord, you can use the :key option to customize it:

class PostSerializer < ActiveModel::Serializer
  attributes :id, :body

  # look up :my_attr on the model, but use +myAttr+ in the JSON
  attribute :my_attr, :key => :myAttr
  has_many :comments
end

または、Ember.String の camelize 組み込み関数に依存する独自の抽出ライブラリを作成するには、http: //emberjs.com/api/classes/String.html#method_camelize を参照してください。

于 2013-05-31T20:16:17.947 に答える