我有以下json文件。
{
"home_page_boolean":true,
"syllabus_page_boolean":true,
"schedule_page_boolean":true,
"hws_page_boolean":true,
"project_page_boolean":true,
"banner_school_image_file":"",
"left_footer_image_file":"",
"right_footer_image_file":""
}
我正试图检查其中一个布尔是真还是假。请注意,我现在的方式是布尔值是一个布尔值而不是字符串值,(它不是“project_page_boolean”:“true”)
这就是我试过的,
if(data.homePageBoolean === true){
navbar+= "<a id='home_link' class='open_nav' href='index.html'>Home</a>";
}
和
if(data.homePageBoolean.toString() === "true"){
navbar+= "<a id='home_link' class='open_nav' href='index.html'>Home</a>";
}
但它不起作用。我很确定解决方案很简单,但我无法弄清楚
答案 0 :(得分:1)
试试这个
if(data['home_page_boolean']){
navbar+= "<a id='home_link' class='open_nav' href='index.html'>Home</a>";
}
答案 1 :(得分:0)
我认为应该如下:
if(data.home_page_boolean === true){
navbar+= "<a id='home_link' class='open_nav' href='index.html'>Home</a>";
}