for-inループ文を使い、2次元の連想配列(単純なオブジェクト)の要素を入れ子でリスト表示する方法。
サンプル
<script type="text/javascript">
var $obj = {
propA: {
propA: "値1-1",
propB: "値1-2",
propC: "値1-3"
},
propB: {
propA: "値2-1",
propB: "値2-2",
propC: "値2-3"
},
propC: {
propA: "値3-1",
propB: "値3-2",
propC: "値3-3"
},
propD: {
propA: "値4-1",
propB: "値4-2",
propC: "値4-3"
},
propE: {
propA: "値5-1",
propB: "値5-2",
propC: "値5-3"
}
};
document . write( '<ol>' );
for ( var $keyA in $obj ) {
document . write( '<li>' );
document . write( '<ol>' );
for ( var $keyB in $obj[$keyA] ) {
document . write( '<li>' );
document . write( $obj[$keyA][$keyB] );
document . write( '</li>' );
}
document . write( '</ol>' );
document . write( '</li>' );
}
document . write( '</ol>' );
</script>
var $obj = {
propA: {
propA: "値1-1",
propB: "値1-2",
propC: "値1-3"
},
propB: {
propA: "値2-1",
propB: "値2-2",
propC: "値2-3"
},
propC: {
propA: "値3-1",
propB: "値3-2",
propC: "値3-3"
},
propD: {
propA: "値4-1",
propB: "値4-2",
propC: "値4-3"
},
propE: {
propA: "値5-1",
propB: "値5-2",
propC: "値5-3"
}
};
document . write( '<ol>' );
for ( var $keyA in $obj ) {
document . write( '<li>' );
document . write( '<ol>' );
for ( var $keyB in $obj[$keyA] ) {
document . write( '<li>' );
document . write( $obj[$keyA][$keyB] );
document . write( '</li>' );
}
document . write( '</ol>' );
document . write( '</li>' );
}
document . write( '</ol>' );
</script>
↓↓↓出力結果↓↓↓