Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过woocommerce order api提交多个产品_Javascript_Angular_Ionic Framework_Woocommerce Rest Api - Fatal编程技术网

Javascript 通过woocommerce order api提交多个产品

Javascript 通过woocommerce order api提交多个产品,javascript,angular,ionic-framework,woocommerce-rest-api,Javascript,Angular,Ionic Framework,Woocommerce Rest Api,我正在尝试使用Woocommerce order api。 我可以根据下面的对象成功提交 data = { "order": { "payment_details": { "method_id": "bacs", "method_title": "direct bank", "paid": false, "stat

我正在尝试使用Woocommerce order api。 我可以根据下面的对象成功提交

        data = {
        "order": {
            "payment_details": {
                "method_id": "bacs",
                "method_title": "direct bank",
                "paid": false,
                "status": "pending"
            },
            "billing_address": {
                "first_name": $scope.f_name,
                "last_name": $scope.l_name,
                "address_1": $scope.address1,
                "address_2": $scope.address2,
                "city": $scope.city,
                "state": $scope.state,
                "postcode": $scope.postcode,
                "country": $scope.country,
                "email": $scope.email,
                "phone": $scope.phone
            },
            "shipping_address": {
                "first_name": $scope.f_name,
                "last_name": $scope.l_name,
                "address_1": $scope.address1,
                "address_2": $scope.address2,
                "city": $scope.city,
                "state": $scope.state,
                "postcode": $scope.postcode,
                "country": $scope.country
            },
            "customer_id": $scope.user_id,
            "line_items": [{
                "product_id": $scope.ids,
                "quantity": 1
            }]
        }
然而,当我需要提交多个产品时,我的问题就出现了。我不知道该怎么做

我知道我可以重复(
“product_id”:$scope.ids,“quantity”:1
)参数,但我不知道用户将提交多少产品,因此这将无效。我的想法是,我需要以某种方式连接所有产品id并推送到对象。请帮忙

此后,我尝试运行for循环来获取所有产品id,并将其附加到名为obj的变量中,然后将该变量添加到对象中,但仍然没有成功

    for (i = 0; i < $scope.basketProducts.length; i++) {
    obj = "product_id:" + $scope.basketProducts[i].id + ",quantity:1";
    console.log(obj);
    }

    "line_items": [{
                    obj
                  }]
for(i=0;i<$scope.basketProducts.length;i++){
obj=“product_id:+$scope.basketProducts[i].id+”,数量:1”;
控制台日志(obj);
}
“行项目”:[{
obj
}]
使用arrays函数连接两个数组的结果

var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var children = hege.concat(stale); 

感谢您的回复,但我不知道会有多少产品,需要动态的,并遵循api的结构