javascript - 检查变量是否存在
问题描述
我正在使用 API Jira 我正在做一些功能,但在使用功能之前,我需要验证一个值是否存在
如果他存在,那么我可以启动其他功能,否则什么也不做。
我正在这样做:
// Call the file functions.js
var functions = require('./functions.js')
/*
Function getAllIssueForSCII displays all the issues in the form of a JSON and that browses all the keys that are in the SCII project
Function pushInitialization initializes the computer score card to 80 on Jira
*/
functions.getAllIssueForSCII().then(function(json){
for (let i=0; i<json.issues.length;i++){
if(json.issues[i].fields.customfield_14038 = null){ // i'm doing this
console.log(json.issues[i].key);
functions.pushInitialization(json.issues[i].key);
}
}
});
/*
A delay is added so that Jira can correctly recover the value 80.
Thanks to this value, we can do all the calculation (Function calculate)
Function pushComputerScoreCard push the final value into the computer score card.
Function generateJSON generates a JSON.
Function replaceCharacter solve the problem of array inside the JSON
*/
setTimeout(function() {
functions.getAllIssueForSCII().then(function(json){
for (let i=0; i<json.issues.length;i++){
functions.calculate(json.issues[i]);
functions.pushComputerScoreCard(json.issues[i].key);
functions.generateJSON(json.issues[i].key);
functions.replaceCharacter();
}
});
}, 1000)
我的问题:设置超时后,他恢复值已经存在并进行计算...
我需要在所有脚本中验证我的状况。
谢谢你的帮助
解决方案
您在 if 条件中分配空值:
if(json.issues[i].fields.customfield_14038 = null){ // i'm doing this
您需要比较值:
if(json.issues[i].fields.customfield_14038 === null){ // You need to do this:
推荐阅读
- appium - Appium - Driver.source() 显示 android 主页,即使屏幕上有应用程序
- python - Python - Django - 修改序列化程序中的字段
- mongodb - Mongo 查询以从集合中获取选择性字段
- symfony - 匹配原则扩展配置
- python-3.x - 无法使用 Python 显示散景图
- delphi - 为什么不按alt键的快捷方式
- typescript - 重命名从 TypeScript 内部库隐式导入的符号
- azure - 如何在 Azure 中对 SQL 数据库资源进行可用性测试?
- r - 用于多行数据的 ggplot 线图 - 与 matplot 等效的 ggplot
- excel - 切片器更改时运行宏