等待加载SharePoint Webparts - 计时问题

时间:2011-02-15 03:04:48

标签: jquery sharepoint sharepoint-2007 web-parts

在同一个SharePoint 2007网站中加载几个webpart时,我遇到了一个时间问题。

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

例如:

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

有没有办法确保webpart与组件最后加载,或者在其他webparts完成加载时开始加载,或者等待代码中的特定点,直到其他webparts完成加载?

webparts以jQuery(js)文件呈现。

感谢。

1 个答案:

答案 0 :(得分:0)

你能在上一个网页部分使用jQuery ready函数吗?

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

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

或者如果你有,在你的网页部分设置某种跟踪数组:

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)
相关问题