javascript - Why can't this be rendered successfully?
高洛峰
高洛峰 2017-05-16 13:26:39
0
2
361
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p id="content"></p>
<script src="jquery-2.2.3.js"></script>
<script src="template-web.js"></script>
<script src="render.js"></script>
<script id="test" type="text/html">
    <h1>{{title}}</h1>
    <ul>
        {{each list as value i}}
        <li>索引 {{i + 1}} :{{value}}</li>
        {{/each}}
    </ul>
</script>
<script>
    var data = {
        title: '标签',
        list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']
    };
    var html = template.render('test', data);
    document.getElementById('content').innerHTML = html;
</script>
</body>
</html>
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
左手右手慢动作

What error was reported? type="text/html" Should this be text/template? Is your data format correct?

伊谢尔伦

There is no need for render.js in artTemplate
The biggest mistake is this sentence
var html = template.render('test', data);
should be changed to
var html = template('test', data);

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template