如何用“dom

编程入门 行业动态 更新时间:2024-10-22 15:25:21
本文介绍了如何用“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

本文发布于:2023-08-02 11:30:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277446.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何用   dom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!