2017-02-21 76 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'