View Full Version : Basic question: how to access my BorderLayout?
dante
24 Aug 2007, 4:35 AM
I have the following (excerpt) and I wonder how to access mainLayout afterwards? My solution so far is to add the line var mainLayout; before this code in order to make mainLayout a global variable. However, this does not seem very elegant, does ext provide a method which returns a reference to the current layout on a page?
var myLayout = function() {
var northPanel, southPanel, eastPanel, eastPanel2, westPanel, centerPanel, center2Panel;
return {
init : function() {
mainLayout = new Ext.BorderLayout(
document.body,
{
north:
{
split: true,
initialSize: 28,
(...)
Animal
24 Aug 2007, 4:37 AM
What's not elegant about it?
dante
24 Aug 2007, 4:51 AM
I was just wondering because in all the examples and tutorials about layouts, the defined layout never gets referenced afterwards. They all stop just when the layout has been defined. You know, as a OOP programmer I have a general distaste for global variables, that's all.
Animal
24 Aug 2007, 4:53 AM
It wouldn't be global.
Jacob
24 Aug 2007, 7:30 AM
Actually in the Dante's sample, "mainLayout" var is global indeed.
This variable is probably declared outside any function.
So, is there any way to retrieve an ExtJS object (e.g : TreePanel, etc...) from a JavaScript function without keeping references to them in global variables initalized during ExtJS objects creation ?
I prefer to keep things stored internal in an object, so my solution for this would be:
var myLayout = function() {
var northPanel, southPanel, eastPanel, eastPanel2, westPanel, centerPanel, center2Panel, mainLayout;
return {
getLayout() {
return mainLayout;
},
init : function() {
mainLayout = new Ext.BorderLayout(
document.body,
{
north:
{
split: true,
initialSize: 28,
(...)
// Can be accessed using myLayout.getLayout()
If you have a bunch of variables then this can get long with all the getters/setters, but it's a decent way to do it.
Another would be to make it a public variable in the object, like this.
var myLayout = function() {
var northPanel, southPanel, eastPanel, eastPanel2, westPanel, centerPanel, center2Panel;
return {
mainLayout: null,
getLayout() {
return myLayout.mainLayout;
},
init : function() {
mainLayout = new Ext.BorderLayout(
document.body,
{
north:
{
split: true,
initialSize: 28,
(...)
// Can be accessed using myLayout.getLayout() OR myLayout.mainLayout
Jacob
24 Aug 2007, 7:43 AM
Thanks !
Animal
24 Aug 2007, 7:46 AM
Actually in the Dante's sample, "mainLayout" var is global indeed.
This variable is probably declared outside any function.
So, is there any way to retrieve an ExtJS object (e.g : TreePanel, etc...) from a JavaScript function without keeping references to them in global variables initalized during ExtJS objects creation ?
There will be in Ext 2.0
All widgets extend Ext.Component, and all Components are registered by id, and retrievable through Ext.getCmp()
Ext 2.0 is going to be awesome!
Wow, that is awesome.
So if I write code that uses Ext 2.0, but I don't have 2.0, about how long do you think it would be before my code would work? :)
Animal
24 Aug 2007, 7:58 AM
You could subclass widgets to register themselves. Ext.ComponentMgr.register() already exists...
I was thinking more along the lines of a timeframe of when 2.0 will be released :)
I don't want to buy a license for 1.0 and then have 2.0 come out a week later, causing me to purchase a 2.0 license...
Jacob
24 Aug 2007, 8:09 AM
Excellent !...
Stay tuned ...
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.