简体   繁体   English

如何在另一个语义ui中添加div?

[英]How can i add a div using semantic ui in another?

i have this function 我有这个功能

createSection = () => {   
     let div = document.createElement("div")
     div.innerHTML =
                    `<section>
                        <Grid centered>
                            <Item.Header  style={{'paddingBottom': '20px', color: 'red'}} as='h1'>{this.state.contents.inputTitle}</Item.Header>
                        </Grid>
                        <Item.Description style={{'maxWidth': '100%'}}>
                            {this.state.contents.inputContent}
                        </Item.Description>
                        <Item.Extra></Item.Extra>
                    </section`             
     document.getElementById("teste").appendChild(div)
}

and i want to add a section in the div 我想在div中添加一个部分

<div onClick={this.createSection} id='teste' style={{'backgroundColor':'#178776', 'boxShadow':'inset 0 3px 27px 19px rgba(15,56,94,.6)', 'borderRadius': '30px', padding: '30px'}}>    
</div>

But what appear in div is: {this.state.contents.inputTitle} {this.state.contents.inputContent} What i have to do for this works correctly? 但是在div中出现的是: {this.state.contents.inputTitle} {this.state.contents.inputContent}我必须做的才能正常工作吗?

@Deborah Luperini, you should not create components in such way in React because it does not vanilla JS, you have to either use JSX, i made working example @Deborah Luperini,您不应该在React中以这种方式创建组件,因为它不支持JS,您必须使用JSX,我做了一个工作示例

or last decision and not the best it a using React.createElement where you need set your parent element, properties and children, i found an example with unordered list, may be it helps you, but i am not recommend use it: 还是最后的决定,而不是最好的决定,它是使用React.createElement ,您需要在其中设置父元素,属性和子元素,我找到了一个无序列表的示例,可能对您有帮助,但我不建议您使用它:

React.createElement("ul", {"className": "ingredients"},
   React.createElement("li", null, "1 lb Salmon"),
   React.createElement("li", null, "1 cup Pine Nuts"),
   React.createElement("li", null, "2 cups Butter Lettuce"),
   React.createElement("li", null, "1 Yellow Squash"),
   React.createElement("li", null, "1/2 cup Olive Oil"),
   React.createElement("li", null, "3 cloves of Garlic")
);

hope it'll help you, good regards 希望能对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM