我想知道常见的方法是如何将大文本导入View.在我的情况下,我正在为Android和iOS开发一个React Native App,在我的一个视图中,我想要呈现"使用条款"文档.现在,当我只是将其导入/复制粘贴到文本组件中时,它就不是正确的解决方案,尤其是当我需要使用本地化来呈现所需的语言时.我将如何"导入"这个文本块,以便它格式化,我不需要将所有内容放入我的视图中:
<View style={styles.container}>
<Text style={styles.text}> |JSON - Text-file, with about 600 words -> Terms of Use document |</Text>
</View>
Run Code Online (Sandbox Code Playgroud)
Dam*_*ryx 15
您可以使用:
import file from './config/TermsAndCondition.json';
Run Code Online (Sandbox Code Playgroud)
然后你可以把它当作一个javascript对象:
file.description
Run Code Online (Sandbox Code Playgroud)
我将它作为JSON,特别是如果你需要带一些其他(元)数据与文本.当fetch(url)被要求componentWillMount和<Text>{this.state.hugeText}</Text>组件填充:
作为一个概念:
constructor(props) {
super(props);
this.state = {
hugeText: ''
};
}
componentWillMount() {
fetch('myText.json')
.then((res) => res.json())
.then((data) => {
this.setState({
hugeText: data.something
});
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13162 次 |
| 最近记录: |