简体   繁体   English

如何在本机反应中更改 select 字段中的值

[英]How to change the value in a select field in react native

I am creating a drop down (using select field) where I want to get the 6 environments below in a drop down, for now the default value is MMP_SSL, so httpLink SERVER_URL is set to MMP_SSL.我正在创建一个下拉列表(使用 select 字段),我想在下拉列表中获取以下 6 个环境,目前默认值为 MMP_SSL,因此 httpLink SERVER_URL 设置为 MMP_SSL。

I would like to change to SD then, httpLink SERVER_URL should be SD.那么我想改成SD,httpLink SERVER_URL 应该是SD。 In the EnvironmentChange function is where I am changing this values, the 6 values are coming from one array.在 EnvironmentChange function 中,我正在更改此值,这 6 个值来自一个数组。

  LOCAL: 'http://localhost:4000',
  LOCAL_IOS: 'http://172.0.0.0',          //change the ip address with the IP of your laptop
  LOCAL_DEMO: 'http://kaushikna.run', // Pointing to Local environment through internet
  MMP: 'http://dclm-mmp1.cluster1.-service', 
  MMP_SSL: 'https://bssmo-service',  //E2E environment 
  SD: 'http://dclmapps.19dclm-service', // Pointing to SD environment


const httpLink = createHttpLink({
  uri: SERVER_URL.MMP_SSL
});

EnvironmentChange = (key, val) => {
    this.handleLanguageChange({ field: "preferredEnv" }, val);
  };

  handleLanguageChange = (props, e) => {
    let tempObj = this.state.preferredEnv;
    tempObj[props.field] = e;
    this.setState({ preferredEnv: e });
  };

let envData = [];
    masterData.language.map(({ code: value, name: label }) => {
      envData.push({ value, label });
    });
    
          <SelectField
                    label="Environment"
                    node="presentationLanguage"
                    options={envData}
                    value={"MMP_SSL"}
                    onChange={this.EnvironmentChange}
                    that={this}
                    setIcon={true}
                  />

Try something like this, I have this piece of code working in react env.尝试这样的事情,我有这段代码在反应环境中工作。

<select value={this.state.preferredEnv}>
  <option value="A">Apple</option>
  <option value="B">Banana</option>
  <option value="C">Cranberry</option>
</select>

The value that you pass as a prop to your SelectField component should be your state variable like so:作为道具传递给SelectField组件的值应该是 state 变量,如下所示:

<SelectField
  label="Environment"
  node="presentationLanguage"
  options={envData}
  value={this.state.preferredEnv}
  onChange={this.EnvironmentChange}
  that={this}
  setIcon={true}
/>

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

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