I am plan use emberjs without ember-data, using Ember.Object. I use rails in back end. The json api rails give is using underscore, I want to change it to camel case in ember end. How to do it effectively? Thanks!
I think you can have two ways of doing this. The first one could be to modify the json rendered by AMS, using the key
modifier
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
or, writing your own extraction lib relying on the camelize built-in fonction of Ember.String, see http://emberjs.com/api/classes/String.html#method_camelize
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.