react如何获取option的下标和值_react中option标签如何确定selected?
生活随笔
收集整理的這篇文章主要介紹了
react如何获取option的下标和值_react中option标签如何确定selected?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我想在react中返回一組option,其中有一個option我想把他設置為selected,不知道如何實現。
大致代碼
render() {
let items = ['a', 'b', 'c', 'd']
.map((fileName) => (
if(fileName == 'd'){
{fileName}
}else{
{fileName}
}
));
return (
onChange={this.onChooseLocale.bind(this)}
defaultValue={Settings.get('locales', 'en-US')}
>
{items}
);
}
不做判斷的話,直接寫
let items = ['a', 'b', 'c', 'd']
.map((fileName) => (
{fileName}
));
但是加了 if else 就不行了。
已經搞定了~ 不用判斷if else, 只需要在option中加上value屬性,
當屬性和option的value相同時,就會自動顯示
總結
以上是生活随笔為你收集整理的react如何获取option的下标和值_react中option标签如何确定selected?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pandas 季度_pandas_时间序
- 下一篇: a律13折线pcm编码例题_a律13折线