HTML   发布时间:2022-04-14  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了if语句 – 如何用“dom-if”在polymer1.0中写入条件?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有下面的代码:
<template is="dom-if" if="{{item.hasAttach}}">
     <i class="fa fa-paperclip"></i>
</template>

item.hasAttach = true / false

但我想检查这个条件,如果像:
item.content_format_code ==’PDF’

<template is="dom-if" if="{{item.content_format_code == 'PDF'}}">
         <i class="fa fa-pdf"></i>
    </template>
<template is="dom-if" if="{{item.content_format_code == 'JPEG'}}">
         <i class="fa fa-jpg"></i>
    </template>
<template is="dom-if" if="{{item.content_format_code == 'xls'}}">
         <i class="fa fa-xls"></i>
    </template>

它应该像{{item.content_format_code ==’PDF’}} = true / false
但它没有测试这个.
我想根据文件类型显示图标. item.content_format_code ==’PDF’未选中true / false.在聚合物中,它仅将真/假作为条件实际值,但不检查表达式.
请帮我.

解决方法

你可以使用 computed bindings.

定义一个计算表达式并将其绑定到dom-if的函数.

<template is="dom-if" if="[[isFormat(item.content_format_code,'PDF')]]">
     <i class="fa fa-pdf"></i>
</template>

Polymer({
    is: "my-element",isFormat: function(code,format) {
        return code === format;
    }
});

大佬总结

以上是大佬教程为你收集整理的if语句 – 如何用“dom-if”在polymer1.0中写入条件?全部内容,希望文章能够帮你解决if语句 – 如何用“dom-if”在polymer1.0中写入条件?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。