我有一个 jquery 函数,它返回购物车的总值。该函数如下所示:
function bakVormTotals(targetClass){
$.getJSON('http://shop.com/cart/?format=json', function(data){
$.each(data.cart, function(index, totals){
$('<strong/>').html('€' + totals.grand_total + '').appendTo(targetClass); // the grand total price
});
});
}
一切正常,除了 totals.grand_total 的结果是
€undefined€undefined€undefined€undefined€undefined€undefined€2404.00
其中 €2404.00 是正确的值。可能我必须摆脱 html 部分,因为这会不断返回值。这个对吗?有没有办法解决这个问题?
如果这可能有帮助,我的 json 看起来像这样(缩小)。
"totals":{"sub_total":"2020.17","taxes":[{"percentage":"0.1900","amount":383.83}],"grand_total":"2404.00"}}
任何帮助表示赞赏