[英]How to pass a html tag in the value of select input in React js?
I am trying to map values in the input field of a select tag but for some reason it gives me [Object object]
.我试图在选择标签的输入字段中映射值,但由于某种原因它给了我
[Object object]
。 When I am not passing another tag in the return of the map statement, the output is coming fine.当我没有在 map 语句的返回中传递另一个标签时,输出正常。 But I guess there is some other way of using html tags in the select value attribute.
但我想在 select value 属性中还有其他一些使用 html 标签的方法。 The react hook used is:
使用的反应钩子是:
const [categories, setCategories] = React.useState([])
And the return statement is:返回语句是:
<label className="filter-label" for="country" multiple>Filter By Category</label>
<select id="country" name="country" className="search-input"
onChange={e => setCategories([...categories, e.target.value])}
value={categories.map(category => <ChipList key={category}
data= {category} />)}
>
<option>{categories.length < 1 ?
"Select category" :
categories.map(category => <ChipList key={category} data={category}
/>)}</option>
<option value="australia1">Select category1</option>
<option value="australia2">Select category2</option>
<option value="australia3">Select category3</option>
</select>
In short how to write something like value={<p>Hello</p>}
in the value attribute of select input without getting [Object object]简而言之,如何在不获取 [Object object] 的情况下在 select 输入的 value 属性中编写类似
value={<p>Hello</p>}
的内容
do u want that on UI inside select it should be shown as你想在 UI 里面选择它应该显示为
<p>Hello</p>
or just Hello
?还是只是
Hello
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.