流星中的HTTP POST阵列数据

问题描述 投票:1回答:1

我需要发布一个数据数组与该行的索引号。 (如果我在括号中没有索引的情况下发送,服务器只接收最后一项)问题是js不允许我在键名中使用括号...

我试图用key[0] : 'value'构建一个包含所有数组数据的字符串,然后将其作为参数之一传递给它,但这也不起作用。

  Meteor.methods({
  submit_order:  function(){
      var test = HTTP.call("POST", "https://example.com/api/",
      {
        headers: 
            { 
              "Content-Type": "application/x-www-form-urlencoded"
            }
         , 
        data : {ApiLogin:'login',
            ApiKey:'key',
            OrderNumber:'ReactTest1',
            Items[0][ProductQty] : '1',  <--- problem is here
            Items[1][ProductQty] : '2'
      },

      },
  function (error, result) {
   if (!error) {
      console.log(result);
  } else{
     console.log("http post error");
  };
  });
}

});

在PHP中它的编写如下:

'Items'             => array(
                            1 => array(

                                'ProductQty'            => 2,
                                ),
                            2 => array(

                                'ProductQty'            => 1,
                                 ),
                            3 => array(

                                'ProductQty'            => 1,

                                )
                            ),
arrays meteor http-post
1个回答
2
投票

你很接近,你只需要按以下方式设置数组:

{
  ApiLogin:'login',
  ApiKey:'key',
  OrderNumber:'ReactTest1',
  Items:[{ProductQty : '1'},{ProductQty : '2'}]
}
© www.soinside.com 2019 - 2024. All rights reserved.