【问题标题】:I am trying to add value in IonSelect multiple but it select only one vallue in react ionic我正在尝试在 Ion Select multiple 中添加值,但它在反应离子中仅选择一个值
【发布时间】:2020-08-24 02:15:30
【问题描述】:

我已经添加了下拉字段,我必须在我发送的下拉列表中显示值,但在这个 ionselect 中它只需要一个下拉值。

const intila={
    primary:[""]

  }
  const[primarySkill,setPrimary]=useState(intila);
  const handleChange=(event:any)=>{
    primarySkill.primary=event.target.value;
    setPrimary(primarySkill);}
const[isSuccess,setSuccess]=useState(false);
   const handleSubmit=(event:any)=>{
     dispatch(postPrimary())
   }
   if(customerData.primary.length>0&&!customerData.isLoading&&!isSuccess){
     for(var i=0;i<customerData.primary.length;i++){
      var primary=customerData.primary[i];     
       primarySkill.primary.push(primary);
      setPrimary(primarySkill); }
     setSuccess(true);
     console.log(primarySkill);
   }
  return (
    <div>
      <IonSelect  className="ion-padding" multiple={true} onIonChange={handleChange} value={primarySkill.primary}>
      {itemCustomers}
      </IonSelect>
      <IonButton onClick={handleSubmit}/>
    </div>)

postPrimary 有 ["Customer 1","Customer 2"]

itemCustomer 有 [客户 1,客户 2,客户 3,客户 4,客户 5[][1]

这里是 UI 的图像视图:[1]:https://i.stack.imgur.com/RdmYz.png

【问题讨论】:

    标签: ionic-framework redux react-tsx


    【解决方案1】:
      const handleChange=(event:any)=>{
        primarySkill.primary = event.detail.value;
        setPrimary(primarySkill);
      }
    

    为我工作

    【讨论】:

    • 在 handleSubmit 中,我在该函数中调用 postPrimary 返回两个数组字符串,如示例:["Customer 1","Customer 2"]。我试图在下拉列表中设置两个客户,但它只接受客户 2。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 2022-01-23
    相关资源
    最近更新 更多