- 监听对象时如果值是null会报错,默认值设置为{};
- for in 只能遍历对象 i in 4是错误的写法;
- 动态获取数组-拼接传参
var arr = [
"单位1",
"单位2",
"单位3",
"单位4",
"单位5"
]
代码语言:javascript复制// 1.数组[]
for (var i = 0; i < arr.length; i ) {
this.defaultData.hostUnitList.push({
[arr[i]]: this.defaultData[arr[i]]
});
}
代码语言:javascript复制// 2.对象{}
for (var i = 0; i < arr.length; i ) {
this.defaultData.hostUnitList[arr[i]] = this.defaultData[arr[i]]
}