我有这句话:pn = r.notFound == "true" ? "Not currently assigned" : "Currently assigned to VPMO " + r.currentAssignment;
并且我需要为“未定义”添加一个条件,然后为其添加一个值。它基本上需要阅读类似...r.notFound == "undefined" then “Already assigned to this project”
else ifr.notFound == “true” then “Not currently assigned”
else
“Currently assigned to VPMO “ + r.currentAssignment;
最佳答案
var pn;
if (r.notFound == 'undefined') { // be aware that this checks for STRING undefined
pn = 'Already assigned to this project';
} else if (r.notFound == 'true') { // be aware that this checks for STRING true
pn = 'Not currently assigned';
} else {
pn = 'Currently assigned to VPMO ' + r.currentAssignment;
}
?
编辑
如果要检查是否定义了变量,请使用:
if (typeof r.notFound === 'undefined')