我想将对象添加到对象数组中。
我的数组在jsfiddle:https://jsfiddle.net/5w4zhw92/中
预期的
var sensors = [
{ id: 'led', name: 'LED', type: { port: '', path: '' } },
{ id: 'temp', name: 'TEMP', type: { path: '' } },
];发布于 2015-05-14 12:53:44
它已经在工作了,你只需要在使用it.Declare sensorType之前先声明变量,然后再使用它。
var sensorType = {
sender: {
port: '',
path: ''
},
receiver: {
path: ''
}
};
var sensors = [
{ id: 'led', name: 'LED', type: sensorType.sender },
{ id: 'temp', name: 'TEMP', type: sensorType.receiver }
];
console.log(sensorType.sender);
console.log(sensors);https://stackoverflow.com/questions/30229440
复制相似问题