0
votes

I am accessing model data using the .find method but how to get records in JSON format from the model? I am getting output from .find() as: (Console log view)

Class {type: function, store: Class, isLoaded: true, isUpdating: true, toString: function…} ember1375269653627: "ember313" __ember1375269653627_meta: Meta _super: undefined get content: function () { isLoaded: true isUpdating: false set content: function (value) { store: Class toString: function () { return ret; } type: Grid.ModalModel __proto: Object

I am new user of this community, so unable to upload image.

2
When i tried to get output in json data format using model.toJSON()i got following error : Uncaught TypeError: Object function () {...........has no method 'toJSON' – Sachin

2 Answers

0
votes

If you're using Ember Model, you do model.toJSON(). If you are trying to get values from the model you should use the getter model.get('name').

0
votes

In javascript to create a JSON out of javascript object you may want to use:

JSON.stringify({name: "John"}); // => "{"name":"John"}"

It works pretty good for plain Ember.Objects. But you may not want to stringify all properties of given object. In such case you should use getProperties method of EmberObject. For example:

var john = Ember.Object.create({firstName: "John", lastName: "Doe", title: "CEO"});
JSON.stringify(john); // => "{"firstName":"John","lastName":"Doe", "title": "CEO"}"

var namesOnly = john.getProperties("firstName","lastName");
JSON.stringify(namesOnly); // => "{"firstName":"John","lastName":"Doe"}"