javascript - 如何在 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 中的外部函数吗?
解决方案
推荐阅读
- css - 将规则应用于同一级别中的所有节点,最后一行中的节点除外
- sql-server - 在一个表中查找可能在第二个表中的多个列中的匹配列记录
- r - ggplot R中geom_bar中离散值的自定义颜色
- python - Tensorflow 2 没有完全连接的函数我该如何模拟呢?
- javascript - 合并对象数组中具有匹配属性的对象
- java - Java 到 Cpp 代码转换,关于 static 和 new 关键字的问题
- arrays - 不可靠的 Google Firebase 交易
- r - 如何创建一个 S4 类 A,它将 S4 类 B 的列表作为其属性?
- laravel - 没有名为“admin”的角色。拉拉维尔
- javascript - C# MVC 在网页编辑器中使用流阅读器/编写器将字符串添加到 HTML 页面