本文讲述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' 的代码
}