7

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 .

1
  • Would you mind setting up a more concrete example, it's difficult to give a good answer without more details. As it stands, sure you can sideload a pojo into the store and create an ember data model. (for future reference, emberjs.jsbin.com is a great place to create an example) Commented Feb 3, 2014 at 23:15

3 Answers 3

3

We can use

this.store.push(this.store.normalize('salary', {id:1,emp_name:'Raju',emp_salary:'5000'}));
Sign up to request clarification or add additional context in comments.

1 Comment

0

Try setting that JSON object as an Ember object instead:

Em.Object.create({salary:{id:1,emp_name:'Raju',emp_salary:'5000'}})

Comments

0

For me this did the trick:

this.get('store').createRecord('model', {payload})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.