[英]Polymer 2.0 dom-if rendering template even though if condition is false
我很難弄清楚為什么我的內部<dom-if" if="{{_isShowCategory(category.name)}}>
模板為什么呈現,即使條件為假。 我打印出布爾結果,並且當category.name
為'account'
, if
條件正確評估為false
,但是模板仍然呈現。
<dom-if if="[[_shouldRenderDrawer]]">
<template>
<!-- Two-way bind `drawerOpened` since app-drawer can update `opened` itself. -->
<app-drawer opened="{{drawerOpened}}" swipe-open tabindex="0">
<a name="account" href="/account">ACCOUNT</a>
<iron-selector role="navigation" class="drawer-list" selected="[[categoryName]]" attr-for-selected="name">
<dom-repeat items="[[categories]]" as="category" initial-count="4">
<!-- NOTE: I've also tried <dom-if if="{{_isShowCategory(category.name)}}> but I get the same result -->
<template is="dom-if" if="{{_isShowCategory(category.name)}}">
<span style="color:black">{{_isShowCategory(category.name)}}</span>
<a name="[[category.name]]" href="/[[category.name]]">[[category.title]]</a>
</template>
</dom-repeat>
</iron-selector>
</app-drawer>
</template>
</dom-if>
_isShowCategory(categoryName){
return !Boolean(categoryName === "account");
// I've also tried return !(categoryName==='account'), which returns the same result as the above
}
只需更改返回的IF語句即可(categoryName!==“ account”); “!” symbol是邏輯上的NOT運算符,這意味着任何正確的事物都將變為false,並且在您的情況下videversa更加棘手,因為您擁有:
在這種情況下是正確的
-(categoryName ===“帳戶”)= TRUE
--布爾值(categoryName ===“ account”)= TRUE
---!Boolean(categoryName ===“ account”)= FALSE,因為不是符號“!”
在這種情況下是虛假的
-(categoryName ===“帳戶”)= FALSE
--布爾值(categoryName ===“ account”)= TRUE,因為布爾值(“ anythingWithAValidValue”)會轉換不同於NULL / undefined的任何值,否則為TRUE,否則為FALSE
--!Boolean(categoryName ===“ account”)= FALSE,因為不是符號“!” 正如我之前提到的。
順便說一句,這不是聚合物問題,請更改您的問題標簽,更適合使用JS / JAVASCRIPT。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.