C# 在CSOM/JSOM中成功使用SP.SOD.executeOrderLayuntileventNotified(func,eventName)?
在我的JSOM()中,我经常使用SP.SOD.executeOrderLayuntilscript加载(func,depScriptFileName)。有没有人成功地使用了SP.SOD.executeOrderLayuntileventNotified(func,eventName)()呢?对于eventName,它是否像“单击”这样简单?我在网上搜索过,但没有找到任何有用的东西。任何反馈都值得赞赏。基本上是指在第一种情况下指定了客户端库文件名的函数之间的区别,例如C# 在CSOM/JSOM中成功使用SP.SOD.executeOrderLayuntileventNotified(func,eventName)?,c#,sharepoint,sharepoint-2010,csom,sharepoint-jsom,C#,Sharepoint,Sharepoint 2010,Csom,Sharepoint Jsom,在我的JSOM()中,我经常使用SP.SOD.executeOrderLayuntilscript加载(func,depScriptFileName)。有没有人成功地使用了SP.SOD.executeOrderLayuntileventNotified(func,eventName)()呢?对于eventName,它是否像“单击”这样简单?我在网上搜索过,但没有找到任何有用的东西。任何反馈都值得赞赏。基本上是指在第一种情况下指定了客户端库文件名的函数之间的区别,例如sp.js(参数depScri
sp.js
(参数depScriptFileName
)。在后一种情况下,应指定事件名称,例如“sp.scriptloaded-sp.js”
(参数eventName
)
以下是来自SharePoint客户端库的声明init.js
:
function ExecuteOrDelayUntilScriptLoaded(func, depScriptFileName) {
depScriptFileName = depScriptFileName.toLowerCase();
var eventName = "sp.scriptloaded-" + depScriptFileName;
return ExecuteOrDelayUntilEventNotified(func, eventName);
}
关于事件名称
事件名称列表存储在名为g_ExecuteOrWaitJobs
的全局变量中。对于每个SharePoint客户端库文件,都使用预定义的事件名称,例如,对于文件sp.clienttemplates.js
,相应的事件名称是sp.scriptloaded-clienttemplates.js
让我们演示如何利用和功能 为此,让我们介绍一个打印
SP.Web
Title属性的简单示例:
function printWebInfo(){
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web,'Title');
ctx.executeQueryAsync(
function(){
console.log(web.get_title());
},
function(sender,args){
console.log(args.get_message());
});
}
在下面的示例中
ExecuteOrDelayUntilScriptLoaded(printWebInfo, "sp.js");
加载SharePoint客户端库sp.js
后,将调用printWebInfo
函数
使用的相同示例如下所示:
var eventName = "sp.scriptloaded-sp.js";
ExecuteOrDelayUntilEventNotified(printWebInfo,eventName);
其中,
“sp.scriptloaded-sp.js”
事件名称用于确定是否加载了sp.js
库。用于检测此问题答案中的SharePoint事件(“\u spEventWebPartAdderReady”):谢谢Thriggle,回答得好谢谢Vadim的帖子,我能够查看g_ExecuteOrWaitJobs中的所有事件,并查看所有事件和良好的使用示例