Any method to access properties of parent objects in Ember?

This question shows how to get the properties of parent views.

Is there a way to achieve this with generic Ember.Object

s. For example, as accessor properties child

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

   }
});

      

+3


source to share


2 answers


I've put together a jsfiddle demonstrating how to update a child with a "parent" property. The main idea is to check for the presence of a child on the parent's creation and watch if the child changes.

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



Hope this helps. Comment you have any questions.

+1


source


Can a parent be passed when creating a child?



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

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

      

+1


source







All Articles