如何在控制台中检查Ember.js对象? [英] How to inspect Ember.js objects in the console?

查看:118
本文介绍了如何在控制台中检查Ember.js对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法得到Ember.js对象在JavaScript控制台中真正包含的内容。如果您执行 console.log(this),几乎可以获得几乎相同的数据结构,如下所示:





这不是超级有用的,它不知道什么属性实际上设置对象。



到目前为止,我找到的唯一方法调试是为任何可想到的名称尝试和 console.log(this.get('whatever')),但很难猜出可用的。



有没有办法深入对象的数据?

解决方案

Ember提供几个帮助从控制台调试对象的方法:



Object.toString 打印任何ember对象的标识

 应用程序.Person = Em.Object.extend()
person = App.Person.create()
person.toString()
// => < App.Person:ember1024> 中

Ember.inspect 将对象转换为有用的字符串描述

  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 返回全部在对象或哈希上定义的键值

  console.log(Ember.keys(this)); 


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 structure for almost any object, something like this:

That's not super helpful, and it gives you no idea what attributes are actually set on the object.

So far, the only way I've found to debug is to try and console.log(this.get('whatever')) for any conceivable name, but it's hard to guess what's available.

Is there any way to dig deeper into the object's data?

解决方案

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));

这篇关于如何在控制台中检查Ember.js对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆