本文講述SharePoint 2013 開發過程中如何使依賴多個JS文件的代碼,等依賴的多個文件下載完成後再執行。
在SharePoint 使用JS開發事我們經常會遇到等依賴的JS文件下載完成後再執行.
SP.SOD.executeFunc("sp.js","SP.ClientContext",customfunction);
SP.SOD.executeFunc("sp.js", customfunction);
第一行代碼表示等待sp.js 加載 完成,並且執行過SP.ClientContext過後執行 customfunction
但是如果依賴於多個JS文件就要用到 SP.SOD.loadMultiple了,這個是SharePoint裏面纔有的:
$(document).ready(function () {
SP.SOD.loadMultiple(['sp.js', 'clientpeoplepicker.js'], customCode);
});
function customCode() {
// 依賴於'sp.js', 'clientpeoplepicker.js' 的代碼
}