我试图了解如何使用功能。
我在functions.js文件中有2个函数:
我还有另一个用于调用函数的文件(index.js),但是调用函数test()遇到了一些问题
Function.js
function getAllIssueForSCII(){
var options = {
...
};
return new Promise(function (resolve) {
request(options, function (error, response, data) {
if (!error && response.statusCode === 200) {
console.log('JIRA login success!!')
var json = JSON.parse(data);
resolve(json);
} else {
console.log('error: ' + response.statusCode + ': ' + data.statusMessage)
}
})
})
}
function test(){
/* We recover the value of the priority and we give it a score according to its value */
var priority = json.issues[i].fields.priority.name;
var score1 = 0 ;
switch (priority){
...
}
}
Index.js
var functions = require('./functions.js')
functions.getAllIssueForSCII().then(function(json){
for (var i=0; i<json.issues.length;i++){
console.log(json.issues[i].key);
functions.test(); //Error
}
});
预先感谢您的帮助