-
14 Jan 2012 10:57 AM #1
this.parent and this.getParent() always return undefined in initialize
this.parent and this.getParent() always return undefined in initialize
I can't seem to get this.parent or this.getParent() to return anything in initialize. I think this is also causing the up() method to not work in initialize. I could be missing an obvious reason why this doesn't work. If I am, please let me know why this is.
Example code:
Code:Ext.define('Bv.Template', { extend: 'Ext.Container', xtype: 'bvtemplate', cls: 'bvtemplate', layout: "vbox", flex: 1, config: { templateData: {}, items: [ { html: "See Console for Output", style: "height: 50px;" } ] }, initialize: function(config) { this.callParent(); this.on("show", function() { console.log("<<<SHOW EVENT") console.log(this.parent) // This works console.log(this.getParent()) // This works console.log(this.up("component")) // This works }) console.log("<<<INSIDE INITIALIZATION") console.log(this) // this actually contains a parent object console.log(this.parent) // undefined console.log(this.getParent()) // undefined console.log(this.up("component")) // undefined } }); Ext.application({ name: 'Bv', launch: function() { var template = Ext.create("Bv.Template", { scrollable: true, fullscreen: true, templateData: {"test":true} }); console.log("<<<AFTER CREATION") console.log(template.parent) // This works console.log(template.getParent()) // This works console.log(template.up("component")) // This works } });Twitter: lylepratt
-
16 Jan 2012 11:25 AM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,659
- Vote Rating
- 14
I don't think it can be there during initialize. Not sure exactly what you are trying to do though where you'd need it.
-
16 Jan 2012 12:32 PM #3
I basically have some dynamic panels are customized when initialized based on an attribute of a parent panel. Would be nice if it were possible to access the parents when initializing something.
Twitter: lylepratt
-
16 Jan 2012 2:28 PM #4Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,659
- Vote Rating
- 14
Initialize is really confined to the instance coming up before it is added to a container.
-
6 Jun 2013 9:14 AM #5
So, if I need to add some logic before the component is added to the DOM, based on the config of the parent it's being added to. Where can I add that if I can't get the parent from within initialize? I would expect that to be the case in the constructor method, but I would think that initialize would have that information available.
The use case is this: I have a "ListTitle" component that I add to a list with ScrollDock: top, among other things. It works fine in most lists, but it's added outside of the scroller if the list is infinite. So, I'm thinking that I need to check if the list it's being added to is infinite, and if it is, then I need to move it inside the scroller.
I'm very new to Sencha, so I very well may be doing this entirely wrong, but this is how the project was originally written.
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote