检查变量是否存在

时间:2019-06-11 08:45:11

标签: javascript jira

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

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

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

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

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