4

次のテンプレートをレンダリングしようとすると、実行時にコンパイル エラーが発生します。

 <script id="tmpl-books" type="text/template">
        <% _.each(items, function(item) { %>
            <ul>
                <li>Title: <%= item.title %></li>
                <li>Author: <%= item.author %></li>
            </ul>
        <% }); %>

    </script>

<script type="text/javascript">
      _.templateSettings = {
                evaluate: /\{\{=(.+?)\}\}/g,
                interpolate: /\{\{(.+?)\}\}/g,
                escape: /\{\{-(.+?)\}\}/g
            };

            var list =
            {
                items:
                [
                    { "title": "Myst: The Book of Atrus", "author": "Rand Miller" },
                    { "title": "The Hobbit", "author": "J.R.R. Tolkien" },
                    { "title": "Stardust", "author": "Neil Gaiman" }]
            };
            $(document).ready(function () {


                var tmplMarkup = $('#tmpl-books').html();
                // ...tell Underscore to render the template...
                var compiledTmpl = _.template(tmplMarkup, list);
                // ...and update part of your page:
                $('#rendered').append(compiledTmpl);
            });
</script>
4

1 に答える 1