如何从下面的对象中检索值?
var recipe= {};
recipe[0, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
recipe[0, 'prodmem_active.tpoint_prod[1].setpoint'] = 1300;
recipe[1, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
recipe[1, 'prodmem_active.tpoint_prod[1].setpoint'] = 1300;
recipe[2, 'prodmem_active.tpoint_prod[0].setpoint'] = 1500;
recipe[2, 'prodmem_active.tpoint_prod[1].setpoint'] = 1200;
e.g。 alert(recipe[1]['prodmem_active.tpoint_prod[1].setpoint'])
不起作用。
答案 0 :(得分:2)
您必须首先正确分配值。
逗号运算符评估为右侧。
此:
recipe[0, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
表示与:
相同recipe['prodmem_active.tpoint_prod[0].setpoint'] = 1600;
您正在尝试创建一个新对象,然后为其中一个新对象属性分配值。
recipe[0] = {};
recipe[0]['prodmem_active.tpoint_prod[0].setpoint'] = 1600;