2011-02-15 63 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)