在 React Native 中从本地 json 文件导入文本 [英] Importing Text from local json file in React native
问题描述
我想知道如何将大文本导入到视图中的常用方法.就我而言,我正在为 Android 和 iOS 开发 React Native 应用程序,并且在我的一个视图中,我想展示使用条款"文档.现在,当我只是将其导入/复制粘贴到文本组件中时,它就不是正确的解决方案,尤其是当我需要使用本地化来呈现所需语言时.我如何导入"这个文本块,这样它的格式很好,我不需要把所有东西都放到我的视图中:
I am wondering how the common way is to import a huge text to a View. In my case i am developing a React Native App for Android and iOS, and on one of my Views i want to present the "Terms of Use" document. Now when i just import/copy paste it into a Text Component it just can´t be the right solution, especially when i need to use localization to present the needed language. How would i "import" this Text-Block so it is nice formatted and i don´t need to put everything into my View:
<View style={styles.container}>
<Text style={styles.text}> |JSON - Text-file, with about 600 words -> Terms of Use document |</Text>
</View>
推荐答案
您可以使用:
import file from './config/TermsAndCondition.json';
然后你可以把它当作一个javascript对象:
then you can treat it as a javascript object:
file.description
这篇关于在 React Native 中从本地 json 文件导入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!