admin管理员组文章数量:1414938
in the response from my server I get a JSON object. It has a boolean flag.
if(file.showInTable == 'true') {
}
But, even if showInTable
is set to false
, I get inside that code block. How to cope with that ?
I tried:
if(file.showInTable == 'true')
if(file.showInTable)
if(Boolean(file.showInTable))
Edit
as Ghommey has mentioned, I've used the 2nd option to check that value. Even if the parions statement returns false
, it also gets inside the code. See the pic below
in the response from my server I get a JSON object. It has a boolean flag.
if(file.showInTable == 'true') {
}
But, even if showInTable
is set to false
, I get inside that code block. How to cope with that ?
I tried:
if(file.showInTable == 'true')
if(file.showInTable)
if(Boolean(file.showInTable))
Edit
as Ghommey has mentioned, I've used the 2nd option to check that value. Even if the parions statement returns false
, it also gets inside the code. See the pic below
- 2 Please post the JSON response you get. – Bojangles Commented Aug 17, 2012 at 8:53
-
What is
typeof file.showInTable
? – xdazz Commented Aug 17, 2012 at 8:53 -
Is it set to the boolean value
false
or the string'false'
? – Anthony Grist Commented Aug 17, 2012 at 8:54 - 1 Duplicate of stackoverflow./questions/263965/… – Sergii Stotskyi Commented Aug 17, 2012 at 8:54
- Anthony Grist: it is set to false or true (as bool) – Tony Commented Aug 17, 2012 at 8:58
2 Answers
Reset to default 2it is set to false or true (as bool) - Tony
Why do you pare a boolean as a string?
Just pare it as a boolean:
if(file.showInTable === true) {
}
or
if(file.showInTable !== false) {
}
This is ugly, but why not?
if (file.showInTable === "false") file.showInTable = false;
本文标签: JavaScript parsing booleanStack Overflow
版权声明:本文标题:JavaScript parsing boolean - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745219531a2648325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论