我计划使用没有 ember-data 的 emberjs,使用 Ember.Object。我在后端使用导轨。json api rails 给出的是使用下划线,我想在 ember 结束时将其更改为驼峰式大小写。如何有效地做到这一点?谢谢!
问问题
1526 次
1 回答
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 回答