如何轻松上传胡子模板?

时间:2014-07-10 10:35:18

标签: jquery html mustache

我开始学习mustache.js,但我试图加载外部模板(template.html)。下面的代码工作正常。但我不喜欢" $。得到(' template.html',... ..."方法。有更短更便宜的方式。例如:< link href =" path / to / template.mustache" rel =" template" id =" templateName" />


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
     <h2>Titles</h2>
    <ul id="talktitles">
    </ul>
    <script src="mustache.js"></script>
    <script src="jquery.js"></script>

    <script>
        $(function() {
            $.getJSON('/data/speakers.json', function(data) {
                //var template = $('#speakers-template').html();

               // console.log(template);
               // var info = Mustache.render(template, data);
               // $('#talktitles').html(info);

  $.get('template.html', function(template, textStatus, jqXhr) {
            var info =Mustache.render($(template).filter('#speakers-template').html(), data);
            $('#talktitles').html(info);
        });

            });
        });
    </script>
</head>
<body>
  <div id="talktitles"></div>
</body>
</html>

0 个答案:

没有答案