提交表单时更改我的JSON数据

时间:2018-08-28 07:16:08

标签: json angular forms

当我提交订单时,JSON如下所示:

{
"QTY": "x",
"ID": "xxx",
"cart_type": "xxx"
}

但是我需要它看起来像以下内容:

{
 data:{
  "QTY": "x",
  "ID": "xxx",
  "cart_type": "xxx"
  }
}

我的ts文件如下:

onAddtoCart(newOrder) {
    console.log(newOrder);
    this.loading = true;
    this.mhttp.addToCart()
    .subscribe((cart: any) => {
      this.loading = false;
      this.saveCartRef(cart.cartRef);
      console.log(newOrder);
    });
  }

1 个答案:

答案 0 :(得分:0)

您可以将newOrder包裹在JS对象中,如下所示:

onAddtoCart(newOrder) {
    const wrappedNewOrder = {data: newOrder}
    // then the rest as before but using wrappedNewOrder
}