"guests": [
{
"guestname": "john smith",
"is_active": false,
"guestheight": "175cm",
"guestprofile": "https://www.example.com"
},
{
"guestname": "david smart",
"is_active": false,
"guestheight": "175cm"
}
]
我想检查guestprofile是否存在。鉴于我目前有一个变量保存我们试图在此处访问的列表的索引,即itemIndex
. 所以基本上我试图if guests[itemIndex]["guestprofile"]
在 handlebars.js 上下文中查询。
如果我直接引用
{{#if guests.0.guestprofile}}
//do something
{{/if}}
它工作正常。但是,如果我用下面的 itemIndex 替换 0 ,一切都坏了......
{{#if guests.itemIndex.guestprofile}}
//do something
{{/if}}
目前我也尝试过
{{#if (lookup guests itemIndex).guestprofile}}
//do something
{{/if}}
{{#if guests[itemIndex].guestprofile }}
//do something
{{/if}}
它们都没有真正起作用。请帮忙,提前谢谢!