简体   繁体   English

根据 select 字段中的选择值填充

[英]Populate based on choice values in select field

I am new to react and had a design challenge to overcome.我是新来的反应并且有一个设计挑战需要克服。 What I want to do is have a set of choice values in the choice field.我想要做的是在选择字段中有一组选择值。 Each choice value will have different set of KPIs and UOMs.每个选择值将具有不同的 KPI 和 UOM 集。 Based on the choice value I selected I should be able to use pop up to select different KPI values.根据我选择的选择值,我应该能够使用弹出到 select 不同的 KPI 值。 Once I select a set of KPI values.一次我 select 一组 KPI 值。 I should be able to display that in the table below.我应该能够在下表中显示它。

Can anybody show me an example of how to do this?任何人都可以告诉我如何做到这一点的例子吗? I am using material ui and react-bootstrap for the same我正在使用材料 ui 和 react-bootstrap

Here is the picture of that below这是下面的图片

在此处输入图像描述

A very simple example:一个非常简单的例子:

function Page(props) {

    const [choice1, setChoice1] = React.useState(null)
    const [choice2, setChoice2] = React.useState(null)
    ... as many as you need
 
    const handleChoice1 = (event) => {
        setChoice1(event.target.value)
    }
    ... as many as you need
 
    return (
        <div>
            Your page here with selections that call your handleChoice functions when users select them
        </div>
        <Popup open={open}>
            <DisplayContent choice1={choice1} choice2={choice2} />
        </Popup>
        
    )
 
 }

Pass your state to <DisplayContent /> and render the correct data accordingly.将您的 state 传递给<DisplayContent />并相应地呈现正确的数据。 Render nothing if they are null.如果它们是 null,则不渲染。

My example is overly simplistic since I don't know how you are implementing anything.我的例子过于简单,因为我不知道你是如何实现任何东西的。

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

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