Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何从React UL/LI中删除HTML_Reactjs_Loops - Fatal编程技术网

Reactjs 如何从React UL/LI中删除HTML

Reactjs 如何从React UL/LI中删除HTML,reactjs,loops,Reactjs,Loops,我有一个ul在React中填充lis并呈现给DOM,但是它们显示了HTML标记和内容 示例:瓦数:1100瓦 我曾多次尝试使用危险的HTML,但不断出现错误(网上唯一的资源是简单的实现) 以下是处理ul/li生成的相关代码: getFeatureList = ((itemDescription) => { return itemDescription[0].features.map((feature, index) => ( <li key={inde

我有一个
ul
在React中填充
li
s并呈现给DOM,但是它们显示了HTML标记和内容

示例:
瓦数:1100瓦

我曾多次尝试使用
危险的HTML
,但不断出现错误(网上唯一的资源是简单的实现)

以下是处理ul/li生成的相关代码:

  getFeatureList = ((itemDescription) => {
    return itemDescription[0].features.map((feature, index) => (
      <li key={index}> { feature }</li>
    ))
  })

  render() {
    const itemDescription = this.state.data ? this.state.data.ItemDescription : null;
    const featureList = itemDescription ? this.getFeatureList(itemDescription) : null;

    return (
      <div className="product-highlights-container">
        <div className="product-highlights-title">product highlights</div>
        <ul className="product-features">
          {featureList}
        </ul>
      </div>
    )
  }
getFeatureList=((itemDescription)=>{
return itemsdescription[0]。features.map((feature,index)=>(
  • {feature}
  • )) }) render(){ const itemsdescription=this.state.data?this.state.data.itemsdescription:空; 常量featureList=itemDescription?this.getFeatureList(itemDescription):空; 返回( 产品亮点
      {featureList}
    ) }

    当我尝试在
    getFeaturedList
    中添加它时,如果我没有弄错的话,
    getFeatureList
    中的
    itemDescription
    的结构如下:

    itemDescription = [
      {
        features: [
          '<strong>Wattage Output:</strong> 1100 Watts',
          '<strong>Number of speeds:</strong> 3', // etc etc
        ]
      }
    ]
    
    或者,您可以使用library并像以下那样使用它:

    import renderHTML from 'react-render-html';
    
    ...
    ...
    
    getFeatureList = ((itemDescription) => {
      return itemDescription[0].features.map((feature, index) => (
        <li key={index}>
          {renderHTML(feature)}
        </li>
      ))
    })
    
    从“react render html”导入renderHTML;
    ...
    ...
    getFeatureList=((itemDescription)=>{
    return itemsdescription[0]。features.map((feature,index)=>(
    
  • {renderHTML(功能)}
  • )) })
    我没有看到任何使用
    危险的西丁神经HTML
    。。。如果你能发一封邮件就太好了。你也许可以这样做。我提到了我在哪里尝试实现它,但它不起作用。但不是它如何不起作用。例如,您收到了哪些错误消息。该功能在正确使用时工作。请知道如何让它工作的人也许能让它为你工作,但前提是他们知道你是如何使用它的……谢谢,我会尽快补充。我最初有react render html,但我得到的是模块未找到错误如果您通过常用方法(npm安装/纱线添加)正确安装软件包,则不应出现模块未找到错误,请务必包含错误持续存在的错误详细信息和代码@jamesi如果我的答案有帮助,请标记为已接受,@James。如果您仍然有问题,请随意添加一些注释:)我得到了
    解析错误:意外的标记,预期为“}”
    ,代码
  • import renderHTML from 'react-render-html';
    
    ...
    ...
    
    getFeatureList = ((itemDescription) => {
      return itemDescription[0].features.map((feature, index) => (
        <li key={index}>
          {renderHTML(feature)}
        </li>
      ))
    })