PDA

View Full Version : How to handle wait for objects to be created with MVC / Ext.Direct



geewhizbang
23 Jul 2009, 3:01 PM
This is my hack so far.

My tab body is loaded with a new element from a MVC view page:

<h2>Forum Page</h2>
<div id="divForumContent"></div>

The code on the tab:

function ForumInit()
{
if (!MyApp.Forum.Init)
{
DirectRequest.GetForumList
(
function(result, response)
{
MyApp.Forum.Init = true;
MyApp.Forum.ForumList = result;
}
, this);
Page.WhenExists.Exec("divForumContent", LoadForum);
}
}

function LoadForum(o)
{
if (!MyApp.Forum.ForumList)
{
o.innerHTML += "<p>This Portal has no Forums</p>";
}
}

The new function I wrote:


function _WhenExists()
{
this.Exec = function(id, funct)
{
if (typeof(id) != "undefined")
{
this.funct = funct;
this.id = id;
this.timer = null;
this.tries = 0;
}
var o = document.getElementById(this.id, true);
if (o != null)
{
if (this.timer != null) self.clearTimeout(this.timer);
closeTimeout(this.timer);
this.funct(o);
}
else
{
this.tries++;
if (this.tries < 20)
{
this.timer = self.setTimeout("Page.WhenExists.Exec()", 50);
}
else
{
alert("Could not find: " + this.id);
}
}
};
}
Page.WhenExists = new _WhenExists();