我的代码:
const orderResultJson = [
{
key: 'Скачайте приложение по ссылке',
value: 'https://google.com'
},
{
key: 'Логин',
value: 'https://instagram.com'
},
{
key: 'Пароль',
value: '849846'
},
];
function DetailsSection({ item }){
return(
<View>
<Text>{item.key}</Text>
<Text> {replaceURLWithHTMLLinks(item.value) ? 'Cсылка' : 'No'} </Text>
</View>
)
}
function replaceURLWithHTMLLinks(text)
{
var expression =
/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
var regex = new RegExp(expression);
var url = text;
url.match(regex) ? true : false;
}
render() {
return (
........
<FlatList
.......
renderItem={({item}) => <DetailsSection item={item} />}
keyExtractor={item => item.key}
/>
.....
}
我在 DetailsSection 函数中有一个条件。逻辑如下:
如果 {item.value} 包含链接,则显示“一些随机文本”
如果不是,只显示什么是“否”
目前,我还没有完全理解这个问题。一切似乎都运行良好,但 DetailsSection 内的条件流仅显示没有。但是在 JSON 中,我确实有超链接。有什么建议吗?
杨__羊羊
红糖糍粑
温温酱
随时随地看视频慕课网APP
相关分类