如何在React框架中使用SpreadJS,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
首先,我們需要在頁面中添加對React的引用:
SpreadJS React Demo
在這個頁面中,我們將使用Babel的預(yù)編譯版本(稱為babel-standalone),因此我們也會添加一個對此的引用:
最后,添加對Spread.Sheets的引用:
在我們編寫任何腳本之前,我們需要定義一個DIV元素來包含Spread實例。我們稱之為“root”。
接下來,在頁面中添加一個腳本元素。我們將把所有的代碼放在這里:
然后,為Spread.Sheets定義一個React組件,以便我們可以定義一個擴(kuò)展React.Component的類:
class ReactSpreadJS extends React.Component{ }
該類需要在其中定義componentDidMount和render函數(shù)。componentDidMount函數(shù)在組件被掛載后立即被調(diào)用,所以我們用它來初始化Spread實例:
componentDidMount() { //In the DidMount life cycle, we initialize Spread Sheet instance, and the host is defined in the Component template. let spread = new GC.Spread.Sheets.Workbook(this.refs.spreadJs, {sheetCount: 3}); if(this.props.workbookInitialized){ this.props.workbookInitialized(spread); } }
接下來,在渲染函數(shù)中定義Spread.Sheets DOM元素:
render() { //Define the Spread.Sheets DOM template return(); }第3步:為組件創(chuàng)建一個應(yīng)用程序類
首先,通過App類定義應(yīng)用程序React組件:
//Define the application react component. class App extends React.Component{ }接下來,添加一個您將調(diào)用ReactSpreadJS組件的渲染函數(shù):
render(){ //In the root component, it include one ReactSpreadJS component. return() }{console.log(spread)}}> 要完成腳本,請告訴React通過使用ReactDOM.render來初始化應(yīng)用程序:
ReactDOM.render( //Main entry, initialize application react component., document.getElementById('root') ); 看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。
文章標(biāo)題:如何在React框架中使用SpreadJS-創(chuàng)新互聯(lián)
分享URL:http://weahome.cn/article/dsjgih.html