0

I want to execute a function getdata() which uses SP.ClientContext. This function gives me some data from different lists on a page. I want to use this data to render my page with jslink.

My Problem:

(function(){

    getdata()

    ctx.Templates = {};
    ctx.Templates.View = myfunction;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();

at this point SP.ClientContext is an undefined function.

when i go this way:

(function(){

  _spBodyOnLoadFunctionNames.push("getdata");

    ctx.Templates = {};
    ctx.Templates.View = test1;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);

})();

it loads the data but the data comes too late for the rendering.

Do you have an idea how i can solve this problem?

0

You could use SP.SOD.

Example:

(function(){
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
    getdata();

    ctx.Templates = {};
    ctx.Templates.View = myfunction;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
    });
})();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.