Javascript 显示多种可能性的特定值
Javascript displaying particular values from multiple possibilities
我有一个具有不同状态(红色、黄色、绿色和 None)的项目列表,这些项目被分配给特定的程序。我需要将分配给程序的最关键颜色分配给变量。如果至少有一个红色我需要显示红色(无论是否有其他黄色或绿色)如果最关键的是黄色我需要显示黄色,不管是否有绿色。如果只有绿色,我需要显示绿色。如果分配了 none,我需要显示 none。下面的代码对于其中的 3 个是可以的,我不知道如何准确地添加 None 到它。所有值都是字符串。
问候
彼得
function getProjectStatusProgram(program){
var status = '';
var grPrgTask = new GlideRecord('project');
grPrgTask.addQuery('u_program', program);
grPrgTask.query();
while (grPrgTask.next()){
if (grPrgTask.overall_health == 'red'){
status = "red";
break;
} else if (grPrgTask.overall_health == 'yellow'){
status = 'yellow';
}
}
if(status =='red' || status =='yellow')
return status;
else
return 'green';
}
理论示例,因为我没有所有相关代码。
/***
Returns a string with following task status priority:
1: "red": if atleast one task has status "red"
2: "yellow": if atleast one task has status "yellow"
3: "none": if atleast one task has status "none"
4: "green": if no task has either status "red", "yellow" or "none"
**/
function getProjectStatusProgram(program){
//REM: Set default status to "green" due to "If there are only greens I need to display Green"
var status = 'green';
var grPrgTask = new GlideRecord('project');
grPrgTask.addQuery('u_program', program);
grPrgTask.query();
while(grPrgTask.next()){
//REM: "If there is at least one red I need to display red( no matter if there are other yellows or greens)"
if(grPrgTask.overall_health == 'red'){
status = "red";
break;
};
//REM: "If the most critical one is yellow I need to display Yellow, not matter if there are greens."
if(grPrgTask.overall_health == 'yellow'){
status = 'yellow'
}
//REM: If current status is still "green" and this tasks status is "none" -> "none"
//REM: Since it is only "green" if all are "green"
else if(status == 'green' && grPrgTask.overall_health == 'none'){
status = 'none'
}
};
//REM: Just return the status
return status
}
我有一个具有不同状态(红色、黄色、绿色和 None)的项目列表,这些项目被分配给特定的程序。我需要将分配给程序的最关键颜色分配给变量。如果至少有一个红色我需要显示红色(无论是否有其他黄色或绿色)如果最关键的是黄色我需要显示黄色,不管是否有绿色。如果只有绿色,我需要显示绿色。如果分配了 none,我需要显示 none。下面的代码对于其中的 3 个是可以的,我不知道如何准确地添加 None 到它。所有值都是字符串。
问候 彼得
function getProjectStatusProgram(program){
var status = '';
var grPrgTask = new GlideRecord('project');
grPrgTask.addQuery('u_program', program);
grPrgTask.query();
while (grPrgTask.next()){
if (grPrgTask.overall_health == 'red'){
status = "red";
break;
} else if (grPrgTask.overall_health == 'yellow'){
status = 'yellow';
}
}
if(status =='red' || status =='yellow')
return status;
else
return 'green';
}
理论示例,因为我没有所有相关代码。
/***
Returns a string with following task status priority:
1: "red": if atleast one task has status "red"
2: "yellow": if atleast one task has status "yellow"
3: "none": if atleast one task has status "none"
4: "green": if no task has either status "red", "yellow" or "none"
**/
function getProjectStatusProgram(program){
//REM: Set default status to "green" due to "If there are only greens I need to display Green"
var status = 'green';
var grPrgTask = new GlideRecord('project');
grPrgTask.addQuery('u_program', program);
grPrgTask.query();
while(grPrgTask.next()){
//REM: "If there is at least one red I need to display red( no matter if there are other yellows or greens)"
if(grPrgTask.overall_health == 'red'){
status = "red";
break;
};
//REM: "If the most critical one is yellow I need to display Yellow, not matter if there are greens."
if(grPrgTask.overall_health == 'yellow'){
status = 'yellow'
}
//REM: If current status is still "green" and this tasks status is "none" -> "none"
//REM: Since it is only "green" if all are "green"
else if(status == 'green' && grPrgTask.overall_health == 'none'){
status = 'none'
}
};
//REM: Just return the status
return status
}