为什么这里没有应用来自模板dom的html
Why does the html from template dom-if not get applied here
考虑以下代码:
<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?
完整的JS Bin演示在这里:https://jsbin.com/dujekefoga/edit?html,输出
编辑:固定JS Bin url
您的表行标记放错了位置,通过更改标记的放置顺序,我更接近您的预期结果。希望这对你有帮助。
https://jsbin.com/quvutugijo/1/edit?html,输出
最后,这就是工作原理。我相信这是最好的解决方案,因为它使用两个非嵌套的dom-if
,并且html是有效的。
我只需要添加一个函数firstDayOfWeek
,如果item.isoWeekday() === 1
,它将返回true。
<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>
相关文章:
- 如何使用JavaScript在没有html dom的情况下隐藏html元素
- 将GET请求(HTML字符串)转换为完整的DOM对象
- 注入的HTML仅在Dom中解释为字符串
- HTML选择,在DOM中选择了正确的选项,但在firefox中显示了错误的项目
- DOM更改后的L20N翻译html
- 如何序列化包括影子 DOM 在内的 HTML DOM
- 创建一个HTML文件,该文件使用DOM在用户每次单击按钮时交换两段内容
- 使用 jQuery 调用 DOM HTML
- 当我认为它不应该重新渲染视图时,如何防止 Meteor 在 html 选择 dom 单击事件上重新渲染视图
- 使用 ajax 更改光滑轮播的 html 后,DOM 不会更新
- 如何选择由 DevExpress constrols 使用 Javascript DOM 技术自动生成的 html “i
- 根据DOM,HTML元素的开始和结束标记之间的内容被称为属性.这个房产的名字是什么
- 为什么这里没有应用来自模板dom的html
- 通过Java加载XML并制作HTML DOM的一部分
- 在DOM(html)上下文中使用角度作用域函数时出现的问题
- Pupulate Dom HTML fom JSON and coffeescript
- 编辑 DOM/HTML 元素
- JavaScript DOM:html 表操作问题
- 如何识别由于Chrome扩展程序而导致的DOM html代码更改
- 在iPad上捕捉点击DOM/HTML/BODY事件