2011-02-15 62 views
0

我正在遇到在同一SharePoint 2007站点中加载几个Web部件时看起来像是计时问题。等待加载SharePoint Webparts - 计时问题

目前我在我的网站上有几个webparts,所有这些webparts都垂直对齐。我想让最底部的webpart加载最后一个,因为它有一个组件会被渲染来执行jQuery .offset().top(在代码执行时获取组件的左上角位置)。目前,每次重新加载页面时,该组件都显示在不正确的位置。唯一一次在正确的地方是当它上面没有其他web部件时。

例如:

WebPartWithComponent页面上的第一个:

WebPartWithComponent <-- component rendered here correctly. 
WebPart1 
WebPart2 
WebPart3 

在页面上的WebPartWithComoonent前面其他的webpart:

Webpart1 
Webpart2 <-- component rendered here instead. 
WebpartWithComponent <-- this is where the component should be rendered 
Webpart4 

有什么方法来确保带有最后加载的组件的Web部件,或者在其他Web部件完成加载时开始加载,或者在代码中的特定点等待,直到另一个我们bparts已完成加载?

Web部件呈现在jQuery(js)文件中。

谢谢。

回答

0

你可以在最后一个web部分使用jQuery ready函数吗?

http://api.jquery.com/ready/

$(document).ready(function() { 
    //do your stuff 
}); 

或者,如果你有一个,安装在你的Web部件某种跟踪数组:

if(typeof(gWebParts)=="undefined") { 
gWebParts = new Array() 
} 
gWebParts[gWebParts.length] = someobject 

然后,当他们已加载,设置一些变量

gWebParts[i].loaded = true 

并在您的最终网页上,设置一个计时器

setInterval(function() { 
    if(gWebParts all loaded) { 
     clearInterval() 
     //do your stuff 
    } 
}, 250)