最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ember.js -- how to console log a model - Stack Overflow

programmeradmin2浏览0评论

Pretty general question here. In my code I am frequently dealing with models:

let model = this.currentModel;

Which seems to be working, but if I

console.log(model);

I see this useless code in the console:

<lc-dash@model:bizinfo::ember904:null>

Does anyone know how to actually log the contents of the model as an object? Also, anywhere I can read about the meaning of this tag?

Pretty general question here. In my code I am frequently dealing with models:

let model = this.currentModel;

Which seems to be working, but if I

console.log(model);

I see this useless code in the console:

<lc-dash@model:bizinfo::ember904:null>

Does anyone know how to actually log the contents of the model as an object? Also, anywhere I can read about the meaning of this tag?

Share Improve this question edited Feb 13, 2017 at 19:37 nem035 35.5k6 gold badges92 silver badges104 bronze badges asked Mar 29, 2016 at 18:39 Daniel ThompsonDaniel Thompson 2,3514 gold badges25 silver badges38 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Does anyone know how to actually log the contents of the model as an object?

The ember data models have a toJSON method that extracts the relevant data for you:

console.log(model.toJSON());

This method uses the JSONSerializer to create the JSON representation.

If you want to log the data in a more app-specific way, you can use serialize:

model.serialize();

which uses the serialization strategy you defined in the store's adapter to create a JSON representation of the model.

Also, anywhere I can read about the meaning of this tag?

All objects in an Ember app, including Ember Data models, inherit from Ember.CoreObject, which has a toString method that prints this representation.

<lc-dash@model:bizinfo::ember904:null>

means:

  • lc-dash is your app name
  • model is the ember type of the object you are logging (can be controller, route etc.)
  • bizinfo is the name of the object you are logging (name of your model, or controller, or route etc.)
  • ember904 is a guId create with Ember.guidFor
  • null is the model's id. You can overwrite this value using the method toStringExtension in your particular model

For parison example, here's how logging your application controller would look:

<lc-dash@controller:application::ember324>
发布评论

评论列表(0)

  1. 暂无评论