3

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 = ???

   }
});
Community
  • 1
  • 1
Panagiotis Panagi
  • 9,927
  • 7
  • 55
  • 103

2 Answers2

1

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 })  
})
Veebs
  • 2,390
  • 13
  • 10
1

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.

Luke Melia
  • 8,389
  • 33
  • 41