同时使用mustache.js和twig

时间:2015-11-23 09:10:08

标签: javascript jquery twig mustache

我想在我的项目中包含mustache.js。我试着用逐字而不是工作来做到这一点。 所以我的脚本是:

<script type="text/javascript">
    $(document).ready(function() {
        // example user list returned from an ajax call...
        var data = {
            users:
                    [{
                        userName: "Billy Bob",
                        userId: "2AE5F6D0-5A70-4EBF-BBAA-C0A11E74BFD8",
                        securityLevel: "Admin",
                        createdDate: "9/12/2012"
                    }, {
                        userName: "Joe Blow",
                        userId: "D0517EAB-5760-4423-86AC-8FA61A847E11",
                        securityLevel: "Regular",
                        createdDate: "9/12/2012"
                    }]
        };

        var template = $('#userListTemplate').html();
        var html = Mustache.to_html(template, data);
        $('#userListWrapper').html(html);
    });
</script>
<script id="userListTemplate" type="text/template">
    <ul id="userList">
        <li class='userListColumnHeader'>User Name</li>
        <li class='userListColumnHeader'>Security Level</li>
        <li class='userListColumnHeader'>Created Date</li>
        <!-- start the user loop -->
        {{#users}}
        <li class='userRow'>
            <span class="userField"><a href='#' class='userLink' userId='{{userId}}'>{{userName}}</a></span>
            <span class="userField">{{securityLevel}}</span>
            <span class="userField">{{createdDate}}</span>
        </li>
        {{/users}}
    </ul>
</script>

在我做的模板中:

{% verbatim %}
    <div id="userListWrapper"></div>
{% endverbatim %}

我确认我包含了胡子的脚本。 由于错误,我有"Unexpected character "#" in the {{#users}}。你能帮我吗 ? Thx提前和抱歉我的英语

0 个答案:

没有答案