不明白为什么我的最后一个项目未定义

时间:2019-07-29 14:42:32

标签: javascript

我正在尝试使用其状态名称说明来订购其他 job 颜色

我不明白为什么我的最后一个项目(颜色和ame未定义,而另一个项目很好...

(最后一部分为示例)。

由于该功能,我正在使用数组并显示。

感谢您的帮助。

var type =  new Array("blue", "yellow", "red", "notbuilt");
var numberThingparkx = new Array(0, 0, 0, 0);
var reds = new Array();


function Thingparkx(response){
var Json = JSON.parse(response);
if(Json.jobs){
  var Data = Json.jobs.map(function(i) {
    var url = i.url.split('//');

    ajaxGet("https://"+AuthString+url[1]+"api/json", Thingparkx);
  });
}else{
  for(var i = 0; i < type.length; i++){
    if(type[i] == Json.color){        
      numberThingparkx[i]++;
      if(Json.color === "red"){  
        nom = new Array(Json.fullDisplayName,Json.description,"error",Json.color);
        reds.push(nom);
      }
      if(Json.color === "yellow"){  
        nom = new Array(Json.fullDisplayName,Json.description,"instable",Json.color);
        reds.push(nom);  
      }                     
    }
  }
}
}


var Data = reds.map(function(i) {
  return {
    "title": {
      "text": i[0]
    },
    "label": {
      "name": i[2],
      "color": i[3],
    },
    "description": i[1]
  };
});
console.log(Data);
push({
  key: '186163-f7e58b30-8a01-0137-f3a4-0af8bc3cd516',//Widget Key
  data: Data
})
.then(response => console.log(response));
 }

实际结果:

[ { title: { text: 'Thingpark-X » tpx-integration-tests build' },
    label: { name: 'error', color: 'red' },
    description: 'Job for tpx-integration-tests build' },
{ title: { text: 'Thingpark-X » Bundles » util build' },
    label: { name: 'error', color: 'red' },
    description: 'Job for util build' },
{ title:
    { text: 'Thingpark-X » Bundles » storage.driver.mongodb build' },
    label: { name: 'instable', color: 'yellow' },
    description: 'Job for storage.driver.mongodb build' },
{ title:
    { text: 'Thingpark-X » Platforms » CI » tpx create accounts' },
    label: { name: undefined, color: undefined },
    description: 'Job for tpx create accounts' } ]

预期结果:

 [ { title: { text: 'Thingpark-X » tpx-integration-tests build' },
    label: { name: 'error', color: 'red' },
    description: 'Job for tpx-integration-tests build' },
{ title: { text: 'Thingpark-X » Bundles » util build' },
    label: { name: 'error', color: 'red' },
    description: 'Job for util build' },
{ title:
    { text: 'Thingpark-X » Bundles » storage.driver.mongodb build' },
    label: { name: 'instable', color: 'yellow' },
    description: 'Job for storage' },
{ title:
    { text: 'Thingpark-X » Platforms » CI » tpx create accounts' },
    label: { name: 'error', color: 'red' },
    description: 'Job for tpx create accounts' } ]

0 个答案:

没有答案