Exploring the capabilities of Ember.js
Is it possible to expose my data model as JSON through a route or controller?
The object saved in the store looks like this:
this.store.createRecord('Person', {
id: 1,
name: this.get('name'),
email: this.get('email')
});
I aim to present this data as a JSON object from either a route or controller without involving any views.
Can this be achieved? Thank you for your assistance!
EDIT The route is defined as follows:
App.ResultRoute = Ember.Route.extend({
model: function() {
return this.store.find('person', 1);
}
});
The '1' specifies that only this record should be fetched. This approach displays the {{name}} and {{email}} in the view corresponding to the Person object. However, I want to obtain just the JSON representation. I attempted the following suggested solution:
App.ResultRoute = Ember.Route.extend({
afterModel: function (model) {
model.get('content').forEach(function (item) {
console.log(item.get('content'));
});
}
});
But an error occurred:
Uncaught Error: Assertion Failed: Error: More context objects were passed than there are dynamic segments for the route: error
What could be causing this error?