簡體   English   中英

無法使用ustry.js呈現簡單的表

[英]cannot render a simple table with dust.js

我在使用ustust.js渲染簡單表時遇到麻煩

此模板:

<table>
    {#hours}
    <tr>
        <td>{dayText}</td>
        <td>{hoursText}</td>
    </tr>
    {/hours}
</table>

輸出:

<table>
    <tr>
        <td></td>
        <td></td>
    </tr>
</table>

而將模板更改為無序列表就可以了:

<ul>
    {#hours}
    <li>{dayText}&nbsp;{hoursText}</li>
    {/hours}
</ul>

這是模型:

{
hours: [
    {dayText: "Mo-Fri ", hoursText: "11:00-22:00"},
    {dayText:"Sat", hoursText: "12:00-22:00"},
    {dayText:"Sun", hoursText: "12:00-21:00"}
    ]
}

模板是使用browser-full-1.1.0.js在瀏覽器中編譯的,我使用的是LinkedIn分支。

我找到了錯誤還是錯過了某些東西?

我已經找到問題的原因。 我的模板源從頁面內的加載:

$("#dust-templates").children().each(function() {
        var compiled = dust.compile($(this).html(), $(this).attr('id'));
        console.log(compiled);
        dust.loadSource(compiled);
    })

問題是瀏覽器沒有逐字傳遞模板html:

{#hours}

{/hours}
<table>
<tbody><tr>
    <td>{dayText}</td><td>{hoursText}</td>
    </tr></tbody>
</table>

因此,按預期效果工作並不奇怪。 如果我將模板存儲為javascript變量,則可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM