好的,这就是我的问题我有一堆使用JSON对象的价格范围,现在我想在示例中动态更改JSON对象调用:
JSON对象:
ranges = {
"range0" : {
"olive" : {"price": 5},
"ebony" : {"price": 8},
"tigerebony" : {"price": 8},
"zebrawood" : {"price": 7},
"mahagony" : {"price": 7},
"pinkivory " : {"price": 7}
},
"range1" : {
"olive" : {"price": 7},
"ebony" : {"price": 10},
"tigerebony" : {"price": 10},
"zebrawood" : {"price": 9},
"mahagony" : {"price": 9},
"pinkivory " : {"price": 9}
}
}
然后问题:
$("handler").click(function(){
$("#range").html(ranges.range_var.material_var.price)//I know this is extremly wrong
}):
我正在尝试将.range_var
和.material_var
替换为具有正确值的变量,该值将根据用户的选择而变化?
答案 0 :(得分:6)
您只需要使用括号表示法:
ranges[range_var][material_var].price