我可以将布尔值与三元运算符中的整数进行比较吗?

时间:2019-05-29 14:52:45

标签: integer conditional-statements return-value boolean-logic

我有一个用于“ user_id”的键值,该值在登录-0之前设置为false。登录后将其设置为user_id(当然也因此命名为:)),我尝试使用三元运算符来比较2,因此,当我单击时,它将直接登录到登录页面,并且如果user_id值更改为假(已登录),它将直接进入跟踪页面。

 data-msg="{'primary':'community','secondary':{{= (parent.user_id != 'false') ? 'community-tracks' : 'sign-in' }} }" 
**************THIS DID NOT WORK******************
  <div class="w25 pt10 clickable active h__k {{= (grandparent.active.primary == 'community') ? 'white' : 'grey' }}"
        data-on-click="publish"
        data-publish="session:active"
        data-msg="{'primary':'community','secondary':{{= (parent.user_id != 'false') ? 'community-tracks' : 'false' }} }" 
    >
        <img src="img/icon_2x_bottomnav_community_active.png" alt="Add to Playlist" class="hh18 h__k"
            data-if="{{= grandparent.active.primary }} == community"
        />
        <img src="img/icon_2x_bottomnav_community.png" alt="Add to Playlist" class="hh18 h__k"
            data-if="{{= grandparent.active.primary }} !== community"
        />
        <br clear="both" />
        <span class="f-small">Community</span>
    </div>

*********THIS WORKS but its not DRY********* 
<div class="w25 pt10 clickable active h__k {{=(grandparent.active.primary == 'community') ? 'white' : 'grey' }}"
        data-if="{{= parent.user_id }} > 0"
        data-on-click="publish"
        data-publish="session:active"
        data-msg="{'primary':'community','secondary':'community-tracks'}" 
    >
        <img src="img/icon_2x_bottomnav_community_active.png" alt="Add to Playlist" class="hh18 h__k"
            data-if="{{= grandparent.active.primary }} == community"
        />
        <img src="img/icon_2x_bottomnav_community.png" alt="Add to Playlist" class="hh18 h__k"
            data-if="{{= grandparent.active.primary }} !== community"
        />
        <br clear="both" />
        <span class="f-small">Community</span>
    </div>
      <!--if the user is not signed in to community -->
 <div class="w25 pt10 clickable active h__k {{= (grandparent.active.primary == 'community') ? 'white' : 'grey' }}"
            data-if="{{= parent.user_id }} == false"
            data-on-click="publish"
            data-publish="session:active"
            data-msg="{'primary':'community','secondary':'false' }" 
        >
            <img src="img/icon_2x_bottomnav_community_active.png" alt="Add to Playlist" class="hh18 h__k"
                data-if="{{= grandparent.active.primary }} == community"
            />
            <img src="img/icon_2x_bottomnav_community.png" alt="Add to Playlist" class="hh18 h__k"
                data-if="{{= grandparent.active.primary }} !== community"
            />
            <br clear="both" />
            <span class="f-small">Community</span>
        </div>

我还使用了由我们的APP以前的开发人员创建的模板语言。 that,这也可能是为什么它不起作用的原因。这也将解释为什么您可能没有看到这种格式。

0 个答案:

没有答案