Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSON object to Ember data Model

I did common modal pop-up for one of the project. For that modal pop-up, I am passing data-model(say Salary model) as a parameter. Sometimes we need to pass model as an object (i.e. instead of salary model we pass salary object). Based on that i am checking if parameter is an instance of ember or an object .

My question is, can we convert object(say salary object) to ember data model (say salary model)?

For eg:- I have a Model like below

App.Salary=DS.Model.extend({
emp_name:DS.attr('string'),
emp_salary:DS.attr('string')
});

Json object
{salary:{id:1,emp_name:'Raju',emp_salary:'5000'}}

For some reasons , I pass ember salary model as an parameter / salary object(JSON) as an parameter

Both are having same data , but salary model will be ember instance . If i change some thing in node , it will reflect in associated models. But for salary object , if change some thing in node , it will not reflect in associated models .

I know salary object is not associated with ember-data model , that's why it will not reflect with salary associated models .

So is there any way to convert that salary object into salary model . So if i change something in the node , it will reflect associated models .

like image 579
maheshiv Avatar asked Feb 03 '14 14:02

maheshiv


1 Answers

We can use

this.store.push(this.store.normalize('salary', {id:1,emp_name:'Raju',emp_salary:'5000'}));
like image 111
maheshiv Avatar answered Sep 20 '22 10:09

maheshiv