2017-02-21 12 views
0

我正在構建SharePoint 2013頁面的Reactjs組件。在SharePoint JSOM中,我可以通過調用GetCurrentCtx()來獲取當前上下文。我想在我的ReactJs組件中調用此方法,但我不知道該怎麼做:如何從Reactjs調用其他庫方法

import React from 'react'; 

class TestComponent extends React.Component { 

    constructor(props){ 
     super(props); 
     this.state = {likesCount:0, listTitle:''}; 
     this.onLike = this.onLink.bind(this); 
    } 

    onLink(e){ 
     e.preventDefault(); 
     var ctx = GetCurrentCtx(); //<- this line doesn't work. 
     this.setState({listTitle:ctx.ListTitle}); 
     return false; 
    } 

    render(){ 
     return (
      <div> 
       <div>List Title: {this.state.listTitle}</div> 
       <div><button onClick={this.onClick}>Get List Title</button></div> 
      </div> 
     ); 
    } 
} 
export default TestComponent; 

任何想法?

回答

0

只是import文件/組件哪裏是你method

+0

我現在面臨的問題是我不具備的功能GetCurrentCtx()的源文件。該功能由SharePoint頁面加載。我可以在嵌入snipplet中調用這個方法。我想這個方法位於SP.js或Core.js中。如果我在組件中導入這個文件,它會捆綁在最終文件中嗎? –

0

是這樣的:

import { GetCurrentCtx } from './filepath_for_this_function_export' 
相關問題