Jade テンプレートを使用して、Harp プロジェクトに取り組んでいます。コンテンツが入力されていますが、_data.json
思ったようにアクセスできません。この JSON 構造を考えると:
{
"mountain-residence": {
"slug": "mountain-residence",
"title": "Mountain Residence",
"lead": "A southeast facing home...",
"thumb": "exterior/entry",
"sections": [
{
"exterior": {
"slug": "exterior",
"title": "Exterior Photos",
"lead": "Embracing an entry...",
"thumb": "terrace",
"photos": [
{
"slug": "southeast",
"alt": "Mountain Room Overlook",
"caption": "Porch, deck and spa terrace"
},
{
"slug": "terrace",
"alt": "Southeast Terrace",
"caption": "Spa deck and landscape terrace"
},
{
"slug": "entry",
"alt": "Entry Courtyard",
"caption": "Entry court and pergola"
},
{
"slug": "porch",
"alt": "Entry Porch",
"caption": "Timber entry shelter"
}
]
}
},
{
"interior": {
"slug": "interior",
"title": "Interior Photos",
"lead": "The interior spaces...",
"thumb": "mountain-room2",
"photos": [
{
"slug": "mountain-room2",
"caption": "Entry opening to the Mountain Room"
},
{
"slug": "dining",
"caption": "Dining Room into Mountain Room"
},
{
"slug": "cellar1",
"caption": "Wine Cellar and Tasting Room"
},
{
"slug": "den",
"caption": "Den and Family Hearth"
}
]
}
},
{
"design-sketches": {
"slug": "design-sketches",
"title": "Design Sketches",
"lead": "A careful site...",
"thumb": "shower",
"photos": [
{
"slug": "schematic",
"caption": "Exterior Elevation Study"
},
{
"slug": "elevation",
"caption": "Elevation Color Studies"
},
{
"slug": "shower",
"caption": "Outdoor stone shower"
}
]
}
}
]
}
}
mountain-residence.sections.exterior.title
("Exterior Photos")のように、配列内の名前付きオブジェクトにアクセスする方法がわかりません。努力してもうまくいきmountain-residence.sections['exterior'].title
ません。で同じプロパティにアクセスできmountain-residence.sections[0].title
、JSON は有効なようですが、その名前でオブジェクトを呼び出す必要があります...これを行う方法はありますか?
たとえば"mountain-residence"
、ページに入力します。私の一般的なアイデアは、各オブジェクトに"sections"
独自のサブページを入力させることでした。そのため、JSON を介して名前で呼び出すことができるようにしたいと考えています。