[英]How can I add multiple elements like <span>, <p> or <div> inside <option> tag of <select> in ReactJs?
Reactjs is not allowing to add any html tags inside option tag. Reactjs不允许在选项标签内添加任何html标签。 It only accepting one string enclosed by { }
它只接受由{}括起来的一个字符串
I want to give some fixed width to the span. 我想给跨度设置一些固定的宽度。
Tried:- 尝试过:-
1. {<span>{country.iso_code}</span>
<span>{country.dialing_code}</span>}
2. <span>{country.iso_code}</span>
<span>{country.dialing_code}</span>
3. <Fragment><span>{country.iso_code}</span>
<span>{country.dialing_code}</span></Fragment>
Code:- 码:-
<select className={styles.selectCompany}
name="country_code"
value={this.state.personFields["country_code"]}
onChange={this.handlePersonFieldsChange}>
<option value="" disabled>Select</option>
{
this.props.countryList ?
this.props.countryList.map((country, index) => {
return (
<option value={country.dialing_code} key={"code_" + index}>
{country.iso_code +" +"+ country.dialing_code}
//This is working line-i.e.only one string line
{
<span>{country.iso_code}</span>
<span>{country.dialing_code}</span>
}
</option>
)
})
: ''
}
</select>
I want to apply fixed width to the spans. 我想将固定宽度应用于跨度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.