Domanda

I need to make sure sp.js is loaded before I call several functions. I currently call them as follows in SP 2013. It works, but I suspect there is a better/more efficient way.

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getCurrUser);
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', evalGroups);
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getDeptMgrs);
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getItemOwner);
È stato utile?

Soluzione

I normally follow as below

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction);

function readyFunction() {
    getCurrUser();
    evalGroups();
    getDeptMgrs();
    getItemOwner();
}

Its more readable!

Altri suggerimenti

For some reason, SP.SOD.executeFunc does not work for me in my SP 2010 environment (I also can't RegisterSOD), but this works nicely. I like the cleanliness of Amal's answer):

ExecuteOrDelayUntilScriptLoaded(readyFunction, "sp.js");

function readyFunction() {
    retrieveWebSite();
    runCode();
    other();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top