1

我必须在 React JS 中渲染 html 对象数组 谁能指导我如何使用 renderHTML 函数。对象的输出是这样的:“

 const items = this.state.Data.map(item => (
      <div key={item._id}>{renderHTML("{item.albComEn}")}</div>

another variation i tried 

const items = this.state.Data.map(item => (
      <div key={item._id}>{renderHTML("item.albComEn")}</div>
    ));

输出我得到 => "item.albComEn" 或 {item.albComEn}

4

2 回答 2

0

您可以尝试使用模板字符串。更多信息

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

const items = this.state.Data.map(item => (
      <div key={item._id}>{renderHTML(`${item.albComEn}`)}</div>

于 2020-02-28T08:36:06.017 回答
0

您还可以使用 React Fragments 的简短语法,即 '<> </>'。使用这些括号来编写 html 代码。呈现时,html 代码将成功编译。例子:

const service = [
        {
            htmlCode: <>
             <div>
               <h2>Application Screening</h2>
               <br />
               <br />
               What you can expect from us:<br />
                -   Your resume will be written by a team of seasoned experts<br />
                -   They will make sure that your Resume presents your strong points,
                    achievements & key skills in a recruiter-friendly format.<br />
             </div>
            </>
        },
]

使用内部渲染方法作为

...
 render(
  <div>
       {service[0].htmlCode}
  <div>
 )
}
于 2021-04-18T13:49:11.177 回答