Как разместить в двух таблицах ReactJS - PullRequest
0 голосов
/ 11 марта 2020

Я хотел бы объяснить мою проблему дня.

в следующем коде я публикую данные, все работает отлично, но я хотел бы иметь возможность разместить в 2 разных таблицах

У вас есть идея, как это исправить?

postbackend = () => {
 const totals =this.props.items.reduce((total,item) => item.quantity + total, 0)
 const newItems = this.props.items.map((item) => {
 const { title, quantity, } = item;
  return {
    title,
    quantity,
    totals
  };
});
const config = {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ ...this.state, items: newItems ,totalsQty: totals , totalComplet: this.props.total , created: new Date().toISOString().slice(11,16)}),
};

const url = entrypoint + "/alluserpls";

fetch(url, config)
.then(res => res.json())
.then(res => {
 if (res.error) {
  alert(res.error); 
  this.props.history.replace("/OrderSummaryPaymentFalseScreen");  // Your Error Page
  } else {
  alert(`film ajouté avec l'ID ${res}!`);
   this.props.history.push("/OderSummaryScreen"); // Your Success Page
  }
 }).catch(e => {
 console.error(e); 
 this.props.history.replace("/OrderSummaryPaymentFalseScreen");  // Your Error Page
 }).finally(() => this.setState({
 redirect: true
}));
}
...