将参数动态传递给 react js 应用程序上的 Web 服务

健力中

我有两个下拉菜单,折扣类型和优惠类型,折扣类型返回四个元素,所以我想要做的是,例如,如果我从该下拉列表中选择选项编号 2,然后调用使用所选索引填充优惠类型下拉列表的 URL,在这种情况下为“2”,因为现在报价类型正在返回全部,因为我正在使用以下 URL 带来全部:http://xxxxxx:8080/services/OfferType/getAll但我想传递报价类型下拉列表的索引而不是 getAll 以获得类似的内容http://xxxxxx:8080/services/OfferType/2

关于如何执行此操作的任何帮助,因为我没有,您将在下面找到我当前的代码:

import React from 'react';

import DropDownMenu from 'material-ui/DropDownMenu';
import MenuItem from 'material-ui/MenuItem';
import Divider from 'material-ui/Divider';

import cr from '../styles/general.css';

export default class ExampleDropdown extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      DiscountTypeData: [],
      OfferTypeData: [],
      DiscountTypeState: '',
      OfferTypeState: ''
    };
    this.handleChange = this.handleChange.bind(this);

    this.renderDiscountTypeOptions = this.renderDiscountTypeOptions.bind(this);
    this.renderOfferTypeOptions = this.renderOfferTypeOptions.bind(this);

    this.handleChangeDiscountType = this.handleChangeDiscountType.bind(this);
    this.handleChangeOfferType = this.handleChangeOfferType.bind(this);

  }

  componentDidMount() {
    const offerTypeWS = 'http://xxxxxx:8080/services/OfferType/getAll';
    const discountTypeWS = 'http://xxxxxx:8080/services/DiscountType/getAll';

    fetch(offerTypeWS)
      .then(Response => Response.json())
      .then(findResponse => {
        console.log(findResponse);

        this.setState({
          OfferTypeData: findResponse.offerTypes
        });
      });

    fetch(discountTypeWS)
      .then(Response => Response.json())
      .then(findResponse => {
        console.log(findResponse);

        this.setState({
          DiscountTypeData: findResponse.discountTypes
        });
      });
  }

  handleChange(event, index, value) {
    this.setState({value});
  }

  handleChangeDiscountType(event, index, value) {
    this.setState({ DiscountTypeState: (value) });
  }

  handleChangeOfferType(event, index, value) {
    this.setState({ OfferTypeState: (value) });
  }

  renderDiscountTypeOptions() {
    return this.state.DiscountTypeData.map((dt, i) => {
      return (
        <MenuItem
          key={i}
          value={dt.text}
          primaryText={dt.text} />
      );
    });
  }

  renderOfferTypeOptions() {
    return this.state.OfferTypeData.map((dt, i) => {
      return (
        <MenuItem
          key={i}
          value={dt.offerTypeDesc}
          primaryText={dt.offerTypeDesc} />
      );
    });
  }

  render() {

    return (
      <div className={cr.container}>
        <div className ={cr.boton}>
          <Divider/>
          <br/>
        </div>
          <div>
            <DropDownMenu
              value={this.state.DiscountTypeState}
              onChange={this.handleChangeDiscountType}>
              <MenuItem value={''} primaryText={'Select discount type'} />
              {this.renderDiscountTypeOptions()}
            </DropDownMenu>
            <br/>
            <DropDownMenu
              value={this.state.OfferTypeState}
              onChange={this.handleChangeOfferType}>
              <MenuItem value={''} primaryText={'Select offer type'} />
              {this.renderOfferTypeOptions()}
            </DropDownMenu>
          </div>
      </div>
    );
  }
}

这是折扣类型服务的响应:

在此处输入图片说明

因此,如果我选择值为“3”的“批量折扣”,那么我想将该 3 传递给优惠类型 URL..

泰米尔克菲尔

您可以fetchcomponentDidMount 中调用handleChangeDiscountTypehandleChangeOfferType就像在 componentDidMount 中调用一样。例子:

handleChangeDiscountType(event, index, value) {
   fetch('http://xxxxxx:8080/services/DiscountType/' + value.id)
    .then(Response => Response.json())
    .then(findResponse => {
        console.log(findResponse);
        this.setState({ DiscountTypeState: findResponse });
    });
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将React基本应用程序上传到服务器

来自分类Dev

在ExpressJS上动态编译和服务React应用程序

来自分类Dev

使用多方将图像从iPad应用程序上传到Node JS服务器

来自分类Dev

如何通过Web服务器在您的应用程序上显示最新数据

来自分类Dev

如何在BlueMix和Android应用程序上连接PHP Web服务?

来自分类Dev

在Azure Node JS Web应用程序上找不到字体.woff 404

来自分类Dev

Node.js Web应用程序上的IBM Watson语音到文本音频转换

来自分类Dev

托管时,内容未显示在angular.js Web应用程序上

来自分类Dev

Azure Web 应用程序上的 Node.js 错误

来自分类Dev

将参数传递给require 7 Web应用程序

来自分类Dev

在解析服务器应用程序上使用Node.js编写服务器端代码

来自分类Dev

将Windows Azure Azure移动服务中的通知推送到html / js Web应用程序

来自分类Dev

如何仅在node.js中的https上执行Web服务/应用程序

来自分类Dev

如何使用C#构建用于用户登录的RESTful Web服务API以在我的iPhone应用程序上使用

来自分类Dev

我未注册服务的Web API ASP.NET MVC6应用程序上的异常

来自分类Dev

通过JavaScript将复杂参数传递给Web API服务

来自分类Dev

在IIS 10上使用React.js运行.net核心Web应用程序时出错

来自分类Dev

无法在Visual Studio C#ASP内的React应用程序上使用Material-UI。NET核心Web应用程序

来自分类Dev

将 Android 应用程序连接到 Heroku 上的 Django Web 服务器的 Postgresql

来自分类Dev

为什么连接在我的本地 XAMPP Apache Web 服务器上 depolyed 的 PHP Web 应用程序上似乎“不安全”?

来自分类Dev

如何在Dart服务器Web应用程序中动态运行dart2js?

来自分类Dev

如何将Node.js Web服务器与Apache Cordova应用程序一起使用

来自分类Dev

Web应用程序的安全性-将凭据传递到Web服务API

来自分类Dev

Wht是将HTML转换为PDF的最佳解决方案(在Azure Web应用程序上)

来自分类Dev

在远程服务器上开发Node.js / React应用程序,并在本地访问它

来自分类Dev

如何将参数传递给Flask Web应用程序中包含的html

来自分类Dev

如何将Azure Web App服务拆分为多个“子Web应用程序服务”?

来自分类Dev

从应用程序关闭在Web服务上创建的MemoryStream

来自分类Dev

将 GitLab Web 应用程序部署到 Azure 应用程序服务

Related 相关文章

  1. 1

    将React基本应用程序上传到服务器

  2. 2

    在ExpressJS上动态编译和服务React应用程序

  3. 3

    使用多方将图像从iPad应用程序上传到Node JS服务器

  4. 4

    如何通过Web服务器在您的应用程序上显示最新数据

  5. 5

    如何在BlueMix和Android应用程序上连接PHP Web服务?

  6. 6

    在Azure Node JS Web应用程序上找不到字体.woff 404

  7. 7

    Node.js Web应用程序上的IBM Watson语音到文本音频转换

  8. 8

    托管时,内容未显示在angular.js Web应用程序上

  9. 9

    Azure Web 应用程序上的 Node.js 错误

  10. 10

    将参数传递给require 7 Web应用程序

  11. 11

    在解析服务器应用程序上使用Node.js编写服务器端代码

  12. 12

    将Windows Azure Azure移动服务中的通知推送到html / js Web应用程序

  13. 13

    如何仅在node.js中的https上执行Web服务/应用程序

  14. 14

    如何使用C#构建用于用户登录的RESTful Web服务API以在我的iPhone应用程序上使用

  15. 15

    我未注册服务的Web API ASP.NET MVC6应用程序上的异常

  16. 16

    通过JavaScript将复杂参数传递给Web API服务

  17. 17

    在IIS 10上使用React.js运行.net核心Web应用程序时出错

  18. 18

    无法在Visual Studio C#ASP内的React应用程序上使用Material-UI。NET核心Web应用程序

  19. 19

    将 Android 应用程序连接到 Heroku 上的 Django Web 服务器的 Postgresql

  20. 20

    为什么连接在我的本地 XAMPP Apache Web 服务器上 depolyed 的 PHP Web 应用程序上似乎“不安全”?

  21. 21

    如何在Dart服务器Web应用程序中动态运行dart2js?

  22. 22

    如何将Node.js Web服务器与Apache Cordova应用程序一起使用

  23. 23

    Web应用程序的安全性-将凭据传递到Web服务API

  24. 24

    Wht是将HTML转换为PDF的最佳解决方案(在Azure Web应用程序上)

  25. 25

    在远程服务器上开发Node.js / React应用程序,并在本地访问它

  26. 26

    如何将参数传递给Flask Web应用程序中包含的html

  27. 27

    如何将Azure Web App服务拆分为多个“子Web应用程序服务”?

  28. 28

    从应用程序关闭在Web服务上创建的MemoryStream

  29. 29

    将 GitLab Web 应用程序部署到 Azure 应用程序服务

热门标签

归档