1

I want to include into my project the mustache.js. I tried to do that with verbatim but not work. So my script is :

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

And in the template I do :

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

I confirm that I include the script for mustache. As error I have "Unexpected character "#" in the {{#users}}. Can you help me please ? Thx in advance and sorry for my english

Harea Costicla
  • 797
  • 3
  • 9
  • 20

0 Answers0