javascript - JSON object call params as variables -


okay here's problem have bunch of price ranges made using json object want dynamically change json object call in example:

json object:

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}                 }  } 

and problem:

$("handler").click(function(){    $("#range").html(ranges.range_var.material_var.price)//i know extremly wrong }): 

i trying substitute .range_var , .material_var for variables holding correct value change according user's choice?

you need use bracket notation:

ranges[range_var][material_var].price 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -