0
Microsoft Recognition ServicesのFace Detection APIからJSONを取得し、結果を表示しています。私はすでにいくつかの結果を作成しており、これは折りたたみ可能な四倍の唯一のものです。Foreachは結果を複製しますか?
JSONオブジェクトのサイズは、0〜8の9です。これは、50人以上のオブジェクトを作成します。各オブジェクトは5個です。
正しいことは、それぞれの人に折り畳みを作成することです。結果は9つの結果になります。
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++);
}
}
}
'objJSON [obj] .faceAttributes.hair.hairColor'の外観はどうですか?完全なJSON構造を見ずに、この質問に答えるのは難しいです。また、 'for..in'を使って配列やオブジェクトを繰り返し処理するべきではありません。別の戦略に従うことがもっと安全です:https://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-a-bad-idea –
のように思えます)count ++ ++ 5 * hairccolor count? –