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?
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.guidFornull
is the model's id. You can overwrite this value using the method toStringExtension
in your particular modelFor comparison example, here's how logging your application controller would look:
<lc-dash@controller:application::ember324>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With