【问题标题】:pass the multiple value in post api? [closed]在post api中传递多个值? [关闭]
【发布时间】:2020-02-25 14:56:31
【问题描述】:

这是我的 post api 请求,我需要来自前端的这些数据:

考虑下面的代码,users_id 实际上是从 localStorage 获取的,而 items_id 来自另一个我从 componentDidMount 调用的 api:

purchaseOrder(){
        const Users_id = localStorage.getItem('id'); // get user_id
        const items_id = this.state.data.id; // get items_id
        console.log(Users_id)
        console.log(items_id)
        PostData('api/purchase-order-item/submit', this.state).then ((result) => {  // how to pass the users id and items id to api?
            let responseJSON = result;
            console.log(responseJSON);
            console.log(this.state)
            });
    }

this.state:

constructor(props){
  super(props);

   this.state ={
      data: [],
      remark: '', //for api 
      quantity: '', // for api
      isLoaded: false,
      redirect: false,
      history: PropTypes.object.isRequired
   }
    this.purchaseOrder = this.purchaseOrder.bind(this);
     this.onChange = this.onChange.bind(this);
 }

【问题讨论】:

    标签: reactjs api message-passing


    【解决方案1】:

    首先从状态中获取remarkquantity,然后传递一个新的普通对象作为API post数据:

    const users_id = localStorage.getItem('id'); // get user_id
    const items_id = this.state.data.id; // get items_id
    const { remark, quantity } = this.state;
    PostData('api/purchase-order-item/submit', { remark, quantity, users_id, items_id }).then ((result) => {
    

    【讨论】:

    • 酷!!!感谢您的指导
    猜你喜欢
    • 2020-11-09
    • 2020-05-09
    • 2022-10-06
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多