【发布时间】:2014-07-18 20:24:19
【问题描述】:
通过 onClick 事件将多维数组传递给 javascript,子数组被只读为object。
这是json_encoded 数组:
{
"products": {
"41::": {
"key": "41::",
"product_id": "41",
"name": "iMac",
"model": "Product 14",
"shipping": "1",
"image": "data/demo/imac_1.jpg",
"option": [],
"download": [],
"quantity": 3,
"minimum": "1",
"subtract": "1",
"stock": true,
"price": 100,
"total": 300,
"reward": 0,
"points": 0,
"tax_class_id": "9",
"weight": 15,
"weight_class_id": "1",
"length": "0.00000000",
"width": "0.00000000",
"height": "0.00000000",
"length_class_id": "1"
}
},
"token": "17263a44810f21b88362f908d2c4be02",
"customer_id": "1"
}
当json_decoded 在 php 中,但在 javascript 中通过 console.log(data) 时完美返回:
{products: Object, token: "17263a44810f21b88362f908d2c4be02", customer_id: "1"}
php:
`<a id="button-checkout" class="button" onclick='checkOut(<?php echo $json; ?>)'>
<span>Process Cart to Order</span></a>`
javascript:
function checkOut(data) {
console.log(data);
return false;
}
我错过了一步吗?
【问题讨论】:
标签: javascript php json multidimensional-array