How to inspect Ember.js objects in the console?

后端 未结 4 899
面向向阳花
面向向阳花 2021-02-03 10:01

Is there any way to get at what an Ember.js object really contains in the JavaScript console. If you do console.log(this), you will get almost the same data structu

相关标签:
4条回答
  • 2021-02-03 10:47

    There is also the App.__container__ object which, if you know what name your objects are registered to the ember app with, will allow you to grab any object you need while debugging from any environment.

    A couple of examples are

    App.__container__.lookup('store:main') # Gets the store
    App.__container__.lookup('controller:blog') # Gets the blog controller
    
    0 讨论(0)
  • 2021-02-03 10:47

    If you're trying to inspect an Ember Data record, you can call the serialize method on it from your console, this will give you the object as your external data source expects.

    0 讨论(0)
  • 2021-02-03 10:53

    Ember provides several methods to help debug an object from console:

    Object.toString prints identity of any ember object

    App.Person = Em.Object.extend()
    person = App.Person.create()
    person.toString() 
    //=> "<App.Person:ember1024>"
    

    Ember.inspect converts the object into a useful string description

    var object = Ember.Object.create({
      firstName: 'Hansi',
      lastName: 'Hinterseer',
      age: 58
    });
    console.log( Ember.inspect(object) );
    // {__ember1331067974108_meta: [object Object] , firstName: Hansi , lastName: Hinterseer , age: 58}
    

    Ember.keys returns all of the keys defined on an object or hash

    console.log(Ember.keys(this));
    
    0 讨论(0)
  • 2021-02-03 10:55

    ember-chrome-devtools is a nice way to solve this problem now...

    0 讨论(0)
提交回复
热议问题