Foreach复制结果?

时间:2017-08-23 18:17:50

标签: javascript json face-recognition

我从Microsoft Recognition Services的Face Detection API获取JSON并显示结果。我已经创建了几个结果,这是唯一一个可折叠的四倍。

JSON对象的大小为9,从0到8。它创建了50个以上的对象,每个人5个。

正确的做法是为每个人创建一个可折叠的,这将产生9个结果。

  

Length duplicate

     

CODE:

function GenerateAttributes__(objJSON){
  var count = 0;
  for(obj in objJSON){
    for(hair in objJSON[obj].faceAttributes.hair.hairColor){
      document.getElementById('face-attributes-information').innerHTML +=

      '<ul class="collapsible" data-collapsible="accordion">' +
        '<li>' +
          '<div class="collapsible-header"><i class="fa fa-id-card-o" aria-hidden="true"></i><strong>People (2)</strong></div>' +

          '<div class="collapsible-body white">' +
            '<ul class="collection">' +
              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle pink" src="img/neoris-icons/moustache.png">' +
                '<span class="title title-collection-content-information">Facial Appearance</span>' +
                '<p><strong>Moustache</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new black badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new black badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<i class="fa fa-question-circle circle red" aria-hidden="true"></i>' +
                '<img class="responsive-img circle pink" src="img/neoris-icons/beard.png">' +
                '<p><strong>Beard</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new black badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new black badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle pink" src="img/neoris-icons/sideburns.png">' +
                '<span class="title title-collection-content-information">Facial Appearance</span>' +
                '<p><strong>Sideburns</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new black badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new black badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +
            '</ul>' +
          '</div>' +

          '<div class="collapsible-body white">' +
            '<ul class="collection">' +
              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle brown" src="img/neoris-icons/female-hair.png">' +
                '<span class="title title-collection-content-information">Hair Color</span>' +
                '<p><strong class="brown-text">Brown</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new brown badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new brown badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle yellow accent-4" src="img/neoris-icons/female-hair.png">' +
                '<span class="title title-collection-content-information">Hair Color</span>' +
                '<p><strong class="yellow-text">Blond</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new yellow accent-4 badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new yellow accent-4 badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle black" src="img/neoris-icons/female-hair.png">' +
                '<span class="title title-collection-content-information">Hair Color</span>' +
                '<p><strong class="black-text">Black</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new black badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new black badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle teal" src="img/neoris-icons/female-hair.png">' +
                '<span class="title title-collection-content-information">Hair Color</span>' +
                '<p><strong class="teal-text">Other</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle grey" src="img/neoris-icons/female-hair.png">' +
                '<span class="title title-collection-content-information">Hair Color</span>' +
                '<p><strong class="grey-text">Gray</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new grey badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new grey badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

              '<li class="collection-item avatar">' +
                '<img class="responsive-img circle red" src="img/neoris-icons/female-hair.png">' +
                '<span class="title title-collection-content-information">Hair Color</span>' +
                '<p><strong class="red-text">Red</strong></p>' +
                '<a href="#!" class="secondary-content">' +
                  '<span class="new red badge" data-badge-caption=" "><strong>1.0 %</strong></span>' +
                  '<span class="new red badge" data-badge-caption=" "><strong>Confidence </strong></span>' +
                '</a>' +
              '</li>' +

            '</ul>' +
          '</div>' +

        '</li>' +
      '</ul>';

      console.log("COUNT OBJ: ", count++);
    }
  }
}

1 个答案:

答案 0 :(得分:0)

你在另一个圈内互动,他的行为是1 *(n),2 *(n),3 *(n)。 检查你的逻辑