これが本当に基本的な質問である場合は申し訳ありませんが、解決しようとしている問題に似た例が見つかりません。
次のコードでネストされた要素の配列にアクセスできない理由と、その配列の要素にアクセスする方法を説明してください。以下のjsonから、2番目の結果から見つかった「Items」配列を取得できません。
次の json が返されます。
{
"d": {
"results": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"__index": 1,
"ID": "someID1",
"Name": "Some Name 1"
},
{
"__index": 2,
"Items": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"ID": "itemID2_1",
"Name": "Item 2_1"
}
]
},
{
"__index": 3,
"Items": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"ID": "itemID3_1",
"Name": "Item 3_1"
}
]
},
...
翡翠のレイアウトは次のとおりです。
- var results=records, col_type='even';
table#results(style="border-collapse:collapse;")
tr
th.result-header Index
th.result-header ID
th.result-header Name
- each r in results
- col_type=col_type=='even' ? 'odd' : 'even'
tr.result-row
- if (!r.Items)
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.__index}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.ID}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.Name}
- else
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.__index}
- each i in r.Items
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{i.ID}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{i.Name}