【发布时间】:2019-09-13 05:39:41
【问题描述】:
我有一个类,我必须检查是否存在要以一种 html 形式(比如超链接)或普通文本显示的项目。
我将对象作为道具。我发现很难使用 fetch 根据返回码正确识别项目是否存在
this.props.item.map(function(item) {
fetch(url+item)(). then (
if(statusCode === 200)
//display hyperlink
return <a href=url+item>{item.a:item.b}</a>
else
//normal text
return <disp>{item.a:item.b}</disp>
)
// But its expecting a return here!
//return <disp>{item.a:item.b}</disp>
})
【问题讨论】:
-
如果您没有对返回的值做任何事情(不是您返回任何值),为什么还要使用 map - map 似乎是 错误的选择
-
在以编程方式从您的应用程序向用户生成的 url 发送请求时要小心,这可能会导致一些安全风险。至少,如果我理解正确的话,听起来这些是用户生成的网址。
-
@JaromandaX 你推荐我用什么?
-
@PatrickRoberts ,是的,它只是对基本 url 的附加。没有xss
标签: javascript arrays reactjs object ecmascript-6