我的代码是这样的:
EquipmentSLRouting
如何描述var obj具有IDE代码实现的能力,例如
var availableCondition = {
property1: {
condition: true,
value: 'value1'
},
property2: {
condition: false,
value: 'value2'
},
}
var obj = {}
for (var key in availableCondition) {
var potentialProperty = availableCondition[key];
if (potentialProperty ['condition']){
obj[key] = potentialProperty['value']
}
}
当我开始输入
时var obj = {
property1: 'value1',
property2: 'value2',
}
IDE以第二种方式完成了属性,但不是第一种方式。
如何在jsDoc中描述对象以完成此操作?
答案 0 :(得分:0)
我相信这是你正在寻找的答案。
var availableCondition = {
property1: {
condition: true,
value: 'value1'
},
property2: {
condition: false,
value: 'value2'
}
}
function createObj(obj) {
var result = {};
for (var key in obj) {
result[key] = obj[key].value;
}
return result;
}
console.log(createObj(availableCondition));
答案 1 :(得分:0)
我找到了解决方案
var availableCondition = {
property1: {
condition: true,
value: 'value1'
},
property2: {
condition: false,
value: 'value2'
},
};
/**
*
* @type {object}
* @property {string} property1
* @property {string} property2
*/
var myObj = {};
for (var key in availableCondition) {
var potentialProperty = availableCondition[key];
if (potentialProperty ['condition']){
myObj[key] = potentialProperty['value']
}
}