Javascript 在使用一些文本REACT.js设置同一div之前,在div上显示图像
我正在制作一个聊天应用程序,在这个应用程序中,我从后端获得响应,并毫不延迟地显示出来。在设置状态Javascript 在使用一些文本REACT.js设置同一div之前,在div上显示图像,javascript,jquery,html,reactjs,jsx,Javascript,Jquery,Html,Reactjs,Jsx,我正在制作一个聊天应用程序,在这个应用程序中,我从后端获得响应,并毫不延迟地显示出来。在设置状态Chat后,我正在将消息映射到的消息。 下面是我从后端得到的响应 var tesBotMessages = this.state.Chat.map(function (msg, key) { <div className="chat chat-left pull-left"> {(msg.Botresponse === undefin
Chat
后,我正在将消息映射到的消息。
下面是我从后端得到的响应
var tesBotMessages = this.state.Chat.map(function (msg, key) {
<div className="chat chat-left pull-left">
{(msg.Botresponse === undefined || msg.Botresponse === "")
? <div className="chat-body chat-bubbles">
<div className="chat-content">
<p>Sorry I don't get it.. :(</p>
<time className="chat-time"></time></div>
</div>
:<div className="chat-body chat-bubbles">
<div className="chat-content" id="textporgress">
<p id="message">{msg.Botresponse}</p>
<time className="chat-time"></time></div>
</div>}
</div>
var-tesBotMessages=this.state.Chat.map(函数(msg,键){
{(msg.Botresponse==未定义的| | msg.Botresponse====“”)
?
对不起,我不明白(
:
{msg.Botresponse}
}
在显示实际的{p>{msg.Botresponse}
之前,我如何在此JSX上显示图像?我首先检查响应是否未定义为null。如果不是null,则显示
我只需要每隔1秒显示一次。您只需要在最后一条消息中显示图像,对吗?是的..一种只在状态中显示最新消息的图像的方式,不需要使用setTimeout,在setTimeout之前将状态变量showImage设置为true,在超时之后将其设置为false。在JSX中,您可以再检查一次条件(key==this.state.Chat.length-1&&this.state.showImage)然后以其他方式显示show标记。您只需在最后一条消息中显示图像,对吗?是的..一种仅将图像显示为状态为最新消息的方式。您需要使用setTimeout并在setTimeout之前将状态变量showImage设置为true,在超时之后将其设置为false。在JSX中,您可以进行更多的条件检查(key===this.state.Chat.length-1&&this.state.showImage)然后显示否则显示标记。