我有一個計算的形式,從一個JSON獲取其值檢索JSON值與jQuery的計算
var shirtsJSON = [
{"pattern": "Delta Adult S/S 5.2oz", "basePrice": 5.68,
"sizes": {"s-xl": 0, "xxl": 0.84},
"colors": {"white": 0, "athletic": 0.12, "color": 0.23},
"numColors": {"1-2": 0, "3-4": 1.60, "5-6": 3.18, "7-8": 4.81, "9-10": 6.39},
"deductions": {"de48pp": 0, "de72pp": .9, "de96pp": 1.35, "de144pp": 2.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 3.28, "oneloc34": 5.41, "oneloc56": 7.52, "oneloc78": 9.69, "oneloc910": 11.80},
"twoLocation": {"twolocnone": 0, "twoloc12": 3.28, "twoloc34": 5.41, "twoloc56": 7.52, "twoloc78": 9.69, "twoloc910": 11.80},
"threeLocation": {"threelocnone": 0, "threeloc12": 3.28, "threeloc34": 5.41, "threeloc56": 7.52, "threeloc78": 9.69, "threeloc910": 11.80},
"fourLocation": {"fourlocnone": 0, "fourloc12": 3.28, "fourloc34": 5.41, "fourloc56": 7.52, "fourloc78": 9.69, "fourloc910": 11.80}},
{"pattern": "Delta Adult S/S 6.1oz", "basePrice": 6.68,
"sizes": {"s-xl": 0, "xxl": 0.84},
"colors": {"white": 0, "athletic": 0.12, "color": 0.23},
"numColors": {"1-2": 0, "3-4": 1.60, "5-6": 3.18, "7-8": 4.81, "9-10": 6.39},
"deductions": {"de48pp": 0, "de72pp": .70, "de96pp": 1.25, "de144pp": 2.47, "de288pp": 2.55},
"oneLocation": {"onelocnone": 0, "oneloc12": 3.28, "oneloc34": 5.41, "oneloc56": 7.52, "oneloc78": 9.69, "oneloc910": 11.80},
"twoLocation": {"twolocnone": 0, "twoloc12": 3.28, "twoloc34": 5.41, "twoloc56": 7.52, "twoloc78": 9.69, "twoloc910": 11.80},
"threeLocation": {"threelocnone": 0, "threeloc12": 3.28, "threeloc34": 5.41, "threeloc56": 7.52, "threeloc78": 9.69, "threeloc910": 11.80},
"fourLocation": {"fourlocnone": 0, "fourloc12": 3.28, "fourloc34": 5.41, "fourloc56": 7.52, "fourloc78": 9.69, "fourloc910": 11.80}},
然後我這裏有最後的結果
$('#48pp').html("Per Piece : " + currency + getMoney(totalPrice));
$('#72pp').html("Per Piece : " + currency + getMoney(totalPrice));
$('#96pp').html("Per Piece : " + currency + getMoney(totalPrice));
$('#144pp').html("Per Piece : " + currency + getMoney(totalPrice));
$('#288pp').html("Per Piece : " + currency + getMoney(totalPrice));
我希望它減去值從扣除JSON我試圖做到這一點:
$('#72pp').html("Per Piece : " + currency + getMoney(totalPrice - shirtsJSON.deductions[0].de72pp));
但它沒有工作,我似乎無法如圖退出。誰能幫忙?
'shirtsJSON [0] .deductions' - 這是很難說沒有看到其餘的代碼和JSON。 – 2012-02-07 15:52:39
您的JSON格式不正確。請參閱:http://jsonlint.com/ – 2012-02-07 15:54:17