首页 > 解决方案 > 检查变量是否存在

问题描述

我正在使用 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)

我的问题:设置超时后,他恢复值已经存在并进行计算...

我需要在所有脚本中验证我的状况。

谢谢你的帮助

标签: javascriptjira

解决方案


您在 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:

推荐阅读