简体   繁体   English

React Native select 默认值为 1

[英]React Native select default value to 1

I hope you all can help me with this problem, I just want that if the selection is no value, the it will automatic 1, and if not, it will get the value of what the user select in the dropdown (I dont have problem with that), My problem is, I just want that if the user dont select in the dropdown menu, it will get automatic 1.希望大家能帮我解决这个问题,我只是希望如果选择没有值,它会自动为1,如果没有,它会在下拉列表中获取用户select的值(我没有问题有了那个),我的问题是,我只想如果用户在下拉菜单中没有 select,它将自动获得 1。

const submitForm = async(valuesToSubmit) => 
{
 console.log("valuesToSubmit:= ", valuesToSubmit['documentId'])
 let _intfmdocument=0,
 if valuesToSubmit['documentId'] !== null{
    _intfmdocument = valuesToSubmit['documentId']
 }else{
    _intfmdocument = 1
 }
 .....

}



<Select 
   isSearchable
   options={docuLoc}
   className={classes.selection}
   value={documentId!== null ? documentId: 1}
   onChange={(itemValue) => {
          setDisplaySelectedDocumentLocation(itemValue)
          setFieldValue("documentLocationsId",itemValue.value)
   }}
   name='documentId'
 />

this is the result of console.log("valuesToSubmit:= ", valuesToSubmit['documentId'])这是console.log("valuesToSubmit:= ", valuesToSubmit['documentId'])的结果

在此处输入图像描述

Sounds like you really just need to set a default value听起来你真的只需要设置一个默认值

Tray adding:托盘添加:

defaultValue={{ label: "whatever the label is", value: 1 }}

somewhere to the attributes某处的属性

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

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