我有以下代码:
<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
发布评论