HTML tags passed within string not rendering fine

2019-07-22 14:37发布

问题:

  • I am new to js,
  • I have a drop down slider working fine.
  • Content shows fine with p tag
  • but within that p tag i need to add another link or list tag
  • If I give it displays the whole a tag but it doesnot render like a normal web page. since I am giving a string. content={PLAYER.accordion(ballInfo, "qwe

    testing

    "
    )}
  • can you tell me how to fix it.
  • providing my code below
     static accordion(ballInfo, content) {
        if (ballInfo.isRetrieving) {
            return (





 <AccordionHeader className="jump-player-question-title jump-submenu-dropmenuHeader" header="ball ball ball ball sjsdsdkjjksddjks?" content={PLAYER.accordion(ballInfo, "qwe <p> testing</p>")} />

 <AccordionHeader className="jump-player-question-title jump-submenu-dropmenuHeader" header="dsknjdsncjdnsjkcsdnjcsdncjkdsn" content={PLAYER.accordion(ballInfo, "asd <a href="#">testing 2</a>")} />

回答1:

I am not a react expert, but can you try with this, replace

<p> {{content}} </p>

With this

<p dangerouslySetInnerHTML={{__html: content}} />