Panagiotis Panagi
Panagiotis Panagi

Reputation: 10087

Any method for accessing parent object properties in Ember?

This question shows how to get properties of parent views.

Is there a way to achieve the same with general Ember.Objects. For example how does the child access properties of App.Parent:

App.Parent = Ember.Object.extend({
  parentProperty: 'someValue',

  child: App.Child.create()  

});

App.Child = Ember.Object.extend({
   init: function(){
     // I don't know which is my parent object
     // but I still want to access the value of `parentProperty`
     // var parentProperty = ???

   }
});

Upvotes: 3

Views: 2009

Answers (2)

Luke Melia
Luke Melia

Reputation: 8389

I put together a jsfiddle demonstrating how to update a child object with a "parent" property. The basic idea is check for the presence of a child on creation of the parent, and watch in case the child changes.

http://jsfiddle.net/KqCXr/6/

Hopefully, it will help. Comment here is you have any questions.

Upvotes: 1

Veebs
Veebs

Reputation: 2388

Can you pass the parent in when you create the child?

App.Parent = Ember.Object.extend({
  parentProperty: 'someValue',

  child: App.Child.create({ parent: App.Parent })  
})

Upvotes: 1

Related Questions