switch语句如下,tempCla是从数据库获取的数据
var cla = []
var temp = this.data.array_building[building_index]
switch(temp){
case 'B5南':cla = tempCla.data[0].claOfBuilding.B5南;break;
case 'B5北':cla = tempCla.data[0].claOfBuilding.B5北;break;
case 'B6南':cla = tempCla.data[0].claOfBuilding.B6南;break;
case 'B6北':cla = tempCla.data[0].claOfBuilding.B6北;break;
case 'B7南':cla = tempCla.data[0].claOfBuilding.B7南;break;
case 'B7北':cla = tempCla.data[0].claOfBuilding.B7北;break;
case 'B8':cla = tempCla.data[0].claOfBuilding.B8;break;
case 'B9':cla = tempCla.data[0].claOfBuilding.B9;break;
default:break;
}
现在不想用switch语句,想用类似cla = tempCla.data[0].claOfBuilding.temp(直接把temp加到后面会提示最上面声明的temp未读取值)形式,请问该如何实现?
没看懂这个跟switch有啥关系?var cla = tempCla.data[0].claOfBuilding[temp]不就行了