如何在SPFx Webpart打字稿文件中使用外部js

时间:2019-06-13 08:09:22

标签: typescript sharepoint web-parts spfx external-js

我正在创建一个SPFx Webpart,它将显示用户数据,我已经创建了基于JSOM的纯.js文件,该文件返回了我SPdata。我想在我的.ts文件中使用该.js文件。我想在webpart和外接程序中使用相同的js代码。

//This is how the code written in SPData.js:

var SPData = {
SPcontext:null,
returnUsers:function(){
   SPData.SPcontext = SP.ClientContext.getCurrent();
   //SP.js code here to connect and return the data
   return Users;
}
};

//NOw I want to use the same code in my ts like this:

export default class HelloWorldWebPart extends 
BaseClientSideWebPart<IC1Props> {
   public render(): void {
  let Users = SPData.returnUsers();
  // further react code to render 
   }
}

0 个答案:

没有答案