首页 > 解决方案 > 如何在 reactJs 中访问其他项目的外部函数?

问题描述

实际上,我有一个 reactJs 组件,它是项目 A (react 应用程序)中存在的“ BasicComponent ”,在其中我正在调用项目 B中存在的函数 GetGraphObj (javascript(jquery+prototype app))。尽管我在 package.json 中将其设置为:“ globals ”:{“GetGraphObj”:true } ,但我无法访问此功能。

这是我的 BasicComponent :

import React, { Component } from "react";   
class BasicComponent extends Component {
    constructor(props) {
        super(props);
    }

    onhandleChange(e) {
        var fldId = this.props.fldId;
        var global_go = GetGraphObj(fldId);
        console.log(global_go);
        console.log(e.target.value);
    }

    render() {
        return ( 
            <input
              onChange={e => this.onhandleChange(e)}/>
        )
    }

}

这是另一个存储库应用程序的功能:

function GetGraphObj(fldid) {
    var go = null;
    if (window.graphObjMap[fldid])
    go = window.graphObjMap[fldid]
    else if (eps && eps.graphObjMap[fldid])
    go = eps.graphObjMap[fldid]   
    return go;
}

我什至尝试过window.GetGraphObj 但似乎不起作用。您知道如何访问 reactjs 中的外部函数吗?

标签: javascriptreactjsglobals

解决方案


推荐阅读