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 badges1 Answer
Reset to default 9Does 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 namemodel
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.guidFornull
is the model's id. You can overwrite this value using the methodtoStringExtension
in your particular model
For parison example, here's how logging your application controller would look:
<lc-dash@controller:application::ember324>