我在项目中有很多文本,因此我制作了一个仅用于文本的js文件,并将此文件添加到index.html,当使用此文件时出现错误,但是在检查代码时我可以看到文本,
import pandas as pd
with open(file, 'r') as f:
data = f.readlines()
# remove the trailing "\n" from each line
data = map(lambda x: x.rstrip(), data)
# each element of 'data' is an individual JSON object.
# i want to convert it into an *array* of JSON objects
# which, in and of itself, is one large JSON object
# basically... add square brackets to the beginning
# and end, and have all the individual business JSON objects
# separated by a comma
data_json_str = "[" + ','.join(data) + "]"
# now, load it into pandas
# (I get stuck here since they are different record types
data_df = pd.read_json(data_json_str)
faBundleForms.js
const forms = {
changeProfitDate: {
note_1: 'user ',
note_2: 'add '
}
};
add to index.html
`<script src="../static/faBundleForms.js" type="text/javascript">`</script>
use to project
我有这个错误
<p>{forms.changeProfitDate.note_1}</p>
答案 0 :(得分:1)
如果您确实要使用全局变量(这是个坏主意),则需要在它们之前使用window.
,例如:<p>{window.forms.changeProfitDate.note_1}</p>
答案 1 :(得分:0)
如果您使用反应,则正确的方法似乎是这样的:
您的文本保存文件:
export const text = ". . . lots of blah . . . "
export const text2 = ...
您可以在任何地方的react项目中导入该文件
import { text } from './yourTextFile'
const App = (props) => {
return(
<div>
<p>{text}</p>
</div>
)
}
export default App