为什么模板dom中的html如果未在此处应用 [英] Why does the html from template dom-if not get applied here
本文介绍了为什么模板dom中的html如果未在此处应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
<div class="container">
<table class="c">
<tr>
<template is="dom-repeat" items="[[days]]" as="o">
<td class$="[[dayClass(o)]]"><span class="d">[[formatDay(o)]]</span></td>
<template is="dom-if" if="[[lastDayOfWeek(o)]]"></tr>
<template is="dom-if" if="[[!lastDayOfCalendar(o)]]"><tr></template>
</template>
</template>
</tr>
</table>
</div>
为什么</tr>
和<tr>
不能应用到html?
Why do the </tr>
and <tr>
not get applied to the html?
此处提供完整的JS Bin演示: https://jsbin.com/dujekefoga/edit?html,输出
Full JS Bin demo here: https://jsbin.com/dujekefoga/edit?html,output
编辑:已修复JS Bin网址
Fixed JS Bin url
推荐答案
最后,这是可行的.而且我认为这是最好的解决方案,因为它可以与两个非嵌套的dom-if
一起使用,并且html是有效的.
At the end, this is what works. And I believe it's the best solution, as it works with two non-nested dom-if
, and the html is valid.
我只需要添加一个函数firstDayOfWeek
,如果item.isoWeekday() === 1
,该函数返回true.
I just needed to add a function firstDayOfWeek
which returns true if item.isoWeekday() === 1
.
<template is="dom-repeat" items="[[days]]" as="o">
<template is="dom-if" if="[[firstDayOfWeek(o)]]"><tr></template>
<td class$="[[dayClass(o)]]"><span class="d">[[formatDay(o)]]</span></td>
<template is="dom-if" if="[[lastDayOfWeek(o)]]"></tr></template>
</template>
这篇关于为什么模板dom中的html如果未在此处应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文