Replace part of string with tag in JSX

前端 未结 12 1243
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 09:39

I\'m trying to replace parts of a string with JSX tags, like so:

render: function() {
    result = this.props.text.replace(\":\",
12条回答
  •  执笔经年
    2020-12-16 10:19

    The following should also work (assumes ES6), The only nuance is that the text is actually wrapped inside a DIV element and not preceded by it, assuming you are going to use CSS for the actual spacing this shouldn't be a problem.

    const result = this.props.text.split(':').map(t => {
      return 
    {t}
    ; });

提交回复
热议问题