PDA

View Full Version : Check if Object Exsists



TheRebelGriz
30 Apr 2007, 6:35 AM
I'm dealing with some dynamic screens, where fields are added and taken away based on some business rules.

My Question is w/Ext how does one check to see if an Object Exists:

Just to simplify the situation the following are two scenarios using the loading image:

1. HTML Page 1 w/Loading Div:
<div id="loading"><div class="loading-indicator">Loading...</div></div>
<p>Hello World</p>

2. HTML Page 2 w/o Loading Div:
<p>Hello World</p>

Both of the above pages include the following code:


Ext.get('loading').remove();

Results:
Page 1 => works just fine
Page 2 => generates an error => " this.el has no properties "

Does anyone know how to eliminate the potential error? I've tried the following w/o success...


if ( Ext.get('loading') )
Ext.get('loading').remove();

Any assistance is greatly appreciated!!!
Thanks in Advance!!

KimH
30 Apr 2007, 6:52 AM
Does anyone know how to eliminate the potential error? I've tried the following w/o success...


if ( Ext.get('loading') )
Ext.get('loading').remove();

Try the following:

if (Ext.get('loading') !== null)
Ext.get('loading').remove();
...or the following:

try {
Ext.get('loading').remove();
} catch (e) {}
The first approach is better, but in some situations you might need the second.