【发布时间】:2022-07-19 22:49:23
【问题描述】:
我从 API 检索警报消息并使用 \r\n 方法加入。它正确加入并正确记录到控制台,但是它没有在新行上显示警报。相反,它只是忽略这些字符并继续到字符串的下一部分。
例子:
//Thunk
if (warningResults && warningResults.length) {
dispatch(
upsertAppNotification(
AppNotificationsCenter.getNotificationByKey(
NotificationKeys.CustomerAlertWarning,
warningResults.join('\r\n')
),
0
)
);
}
我将通知记录到控制台,它显示如下:
Message: "Warning Message One\r\nWarning Message Two,
这是显示消息的代码:
{props.message && (
<StyledTextBox data-testid={props.messageTestId} maxWidth="80%">
<Typography variant="paragraph">{props.message}</Typography>
</StyledTextBox>
)}
【问题讨论】:
-
HTML 不尊重
\r,您需要使用line break element (<br>) - 或使用stackoverflow.com/questions/39325414/line-break-in-html-with-n 中的解决方案 -
也不行 -
它会奏效,但如果你没有说明为什么你的努力没有奏效,我们将无能为力。 (请勿在 cmets 中发布代码)
标签: javascript reactjs typescript redux