我已经设置了这个js对象:
var tableTypes = {
"stockRcmnd":{
"name":"stockRcmnd",
"columns": ['1','2', '3']
},
"stockChange":{
"name":"stockChange",
"columns": ['4','5', '6']
}
};
现在,我想动态地获取列:
property = "stockChange";
columns = tableTypes.{property}.columns;
property = "stockRcmnd";
columns = tableTypes.{property}.columns;
here是jsfiddle;
任何想法怎么做?
答案 0 :(得分:1)
也可以在JavaScript中访问对象属性:
tableTypes[property].columns
答案 1 :(得分:0)
只需:
tableTypes['stockRcmnd'].name