React Native:在组件中<Text></Text>将字符串渲染为JavaScript代码



在我的react原生应用程序中,我用Json文件中填充的列表渲染一个faq屏幕,并在FlatList中渲染,在一些字符串中有指向操作的链接或调用,如下所示:

"Estan quebrantando las <Text onPress={ ()=>{ root.mapStore.openUrl('https://page.com/privacy-policy') } } style={{ color:'#F37F06' }}>Reglas de la comunidad</Text> o <Text onPress={ ()=>{ root.mapStore.openUrl('https://page.com/privacy-policy') } } style={{ color:'#F37F06' }}>Términos y condiciones</Text>" 

如何正确地将字符串呈现为内联文本组件:

<Text>{ jsonBody }</Text>

您可以使用json作为

{
"faq":[
{"text":"some text", "script":"some script", "link": "some link"},
{"text":"some text", "script":"some script", "link": null},
{"text":"some text", null, "link": "some link"},
]
}

并根据需要处理文本、脚本和链接

由于没有关于json的完整信息以及您想对该脚本做什么的问题,因此将其视为codestring,无法提供足够的解决方案

最新更新