如何用“dom-if”?在polymer1.0中写入条件? [英] How do I write condition in polymer1.0 with "dom-if"?

查看:131
本文介绍了如何用“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'

But I want to check condition in this if like : 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 。在聚合物中,它仅将真/假作为条件实际值,但不检查表达式。
请帮助我。

it should be like {{item.content_format_code == 'PDF'}} = true/false But it is not testing this. I want to show icon as per file type. item.content_format_code == 'PDF' this is not checked true/false. In polymer it takes only true/false as a conditional actual value but don't check expression. Please Help me.

推荐答案

您可以使用计算绑定

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

Define a function that computes the expression and bind it to the 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;
    }
});

这篇关于如何用“dom-if”?在polymer1.0中写入条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆