Javascript 从字符串解析标记并作为JSX返回
因此,我的后端返回一个包含两组强标记的字符串。看起来像:Javascript 从字符串解析标记并作为JSX返回,javascript,reactjs,react-native,Javascript,Reactjs,React Native,因此,我的后端返回一个包含两组强标记的字符串。看起来像: const string = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>" const string=“Name N.你今天过得怎么样?更多文本 因为我使用的是react native,所以无法按原样显示它。我想返回如下内容: const string =
const string = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>"
const string=“Name N.你今天过得怎么样?更多文本
因为我使用的是react native,所以无法按原样显示它。我想返回如下内容:
const string = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>"
名字。
你今天好吗?
更多文本
最好的办法是什么
谢谢:)你可以用两种方法来做 第一选项 通过网络视图
const string = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>"
<WebView source={{html: string}} />
const string=“Name N.你今天过得怎么样?更多文本
第二选项
通过替换和拆分
const text=“Name N.你今天过得怎么样?更多文本”;
const[first,second,third]=text.replace(/(|)/g,“|”).split(“|”).filter(cur=>cur.map(cur=>cur.trim());
console.log(第一);
console.log(第二个);
控制台日志(第三)你可以像那样使用