edit this page - page history - about editing

Listing the Attributes of an EmberJS DS.Model at Runtime

EmberJS

With some hackery, you can list all of the attributes (not computed properties) of any given DS.Model type at EmberJS runtime, based on this answer (and also references Transient DS.Model Attributes in EmberJS):

Ember.run ->
  type = "myModel"
  model = App.__container__.lookup('store:main').createRecord(type)
  model.eachAttribute (name, attribute) ->
    if attribute.isAttribute and not attribute.options.transient?
      console.log type + " has attribute " + name

You should not be using this in production code - strictly for debugging and testing only.
Categories: Javascript | EmberJS
edit this page - what links to here? - page history - top
Last edited by jevon jevon 41 months ago