Why does the html from template dom-if not get applied here

前提是你 提交于 2020-01-06 16:09:09

问题


Consider this code:

<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>

Why do the </tr> and <tr> not get applied to the html?

Full JS Bin demo here: https://jsbin.com/dujekefoga/edit?html,output

Edit: Fixed JS Bin url


回答1:


Your table row tags are misplaced, I got closer to your expected result by changing the order in which the tags are placed. Hope this helps you.

https://jsbin.com/quvutugijo/1/edit?html,output




回答2:


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.

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>     


来源:https://stackoverflow.com/questions/36703371/why-does-the-html-from-template-dom-if-not-get-applied-here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!