【问题标题】:Trouble with dynamic HTML table with Mustache & Icanhazjs带有 Mustache 和 Icanhazjs 的动态 HTML 表的问题
【发布时间】:2013-02-16 12:16:15
【问题描述】:

我正在尝试使用 Icanhazjs (Mustache) 构建一个动态表。表格数据总是在表格标签之外呈现,因此不会将我的数据放入表格中。

您可以在我的 JSfiddle Here 中看到输出

这是我的 HTML:

<script id="display_row" type="text/html">
    <tr>
        <td>{{data1}}</td>
        <td>{{data2}}</td>
        <td>{{data3}}</td>
    </tr>
</script>

<h1>Icanhazjs & Mustache Table Test</h1>
<table border="1">
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
    </thead>
    <tbody>
        <div id="table_list"></div>
    </tbody>
</table>

这里是 Javascript:

$(document).ready(function () {
    var user_data, user;

    user_data = [
        {
            data1: "foo1",
            data2: "foo2",
            data3: "foo3"
        },
        {
            data1: "foo4",
            data2: "foo5",
            data3: "foo6"
        }
    ];

    for (i=0; i<user_data.length; i++) {
        user = ich.display_row(user_data[i]);
        $('#table_list').append(user);
    }
});

谁能解释为什么数据没有在我的 html 表中的&lt;div id="table_list"&gt;&lt;/div&gt; 点呈现。 icanhazjs 正在工作,但只是将呈现的 html 放在我的桌子之前。

【问题讨论】:

    标签: html mustache icanhaz.js


    【解决方案1】:

    代替

    <tbody>
        <div id="table_list"></div>
    </tbody>
    

    试试这个:

    <tbody id="table_list">
    </tbody>
    

    JSFiddle:

    http://jsfiddle.net/sapy7/1/

    【讨论】:

    • @fatfantasma:别忘了将我的答案标记为正确。支持答案也会很好:)
    猜你喜欢
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多