JSLink: Render after SP-functions were executed
-
01-10-2020 - |
質問
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?
解決
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);
});
})();
所属していません sharepoint.stackexchange