直接来代码吧!

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul id="wrap">
<script id="tpl" type="text/html">
<%if(result){%>
<%for(var i=0;i<result.length;i++){%>
<li><%=result[i].area_name%></li>
<%}%>
<%}%>
</script>
</ul>
<script src="js/jquery/jquery-1.8.3.min.js" ></script>
<script src="js/template/template.js"></script>
<script>
$(function(){ $.ajax({
type: "get",
url: "js/json/package.json",
data:{//后台需要的参数
flag:"wap"
},
dataType: "json",
success: function(data){
// var data = {
// result: [
// {
// area_id: "535",
// area_name: "美国",
// pid: "45055"
// },
// {
// area_id: "536",
// area_name: "加拿大",
// pid: "45055"
// }
// ],
// error: "0",
// msg: "",
// total: 0,
// hasmore: false
// } if (data && data.error === "0") {
console.log(data);
var html = template.render('tpl',data);
$('#wrap').html(html);
}
}
});
});
</script>
</body>
</html>
package.json:
{
"result": [
{
"area_id": "535",
"area_name": "美国",
"pid": "45055"
},
{
"area_id": "536",
"area_name": "加拿大",
"pid": "45055"
}
],
"error": "0",
"msg": "",
"total": 0,
"hasmore": false
}

需要的js文件就是 template.js和jQuery

(template.js查看文件)!!!!

我是这样使用template.js来异步渲染数据的demo的更多相关文章

  1. 我是这样使用template.js来异步渲染数据的

    总监的代码用的是define+module.exports,为了效率先没去了解那一块,在github上找了一款功能单一的template.js来使用 https://github.com/yanhai ...

  2. template.js文档

    参见GitHub:https://github.com/yanhaijing/template.js/ template.js简介: template.js 一款javascript模板引擎,简单,好 ...

  3. 前端-使用template-web.js【模版引擎】渲染数据

    通过ajax请求到的数据,使用传统的拼接字符串也可以做到,但是‘ “ ” ‘这种模式,单引号.双引号容易 扩错,新手入门推荐使用这种,初入前端,需要一个一个敲代码体会一下. 使用 template.j ...

  4. 出位的template.js 基于jquery的模板渲染插件

    找了好几款基于jquery的模板渲染插件,无一感觉很难用(教程较少.绑定不统一),也可能我智商问题,比如jquery template.js .jtemplate.js. 然后在github上找到这一 ...

  5. template.js 数据渲染引擎

    template.js 数据渲染引擎 template.js是一款JavaScript模板引擎,用来渲染页面的. 原理:提前将Html代码放进编写模板 <script id="tpl& ...

  6. js模板(template.js)实现页面动态渲染

    template.js是由纯JavaScript编写的第三方模板引擎.点击https://github.com/yanhaijing/template.js可进行下载. 在页头导入模板文件 <s ...

  7. vue 异步渲染

    <!DOCTYPE html> <html> <head> <title> hello world vue </title> <met ...

  8. 关于vue.js中列表渲染练习

    html: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8 ...

  9. 从壹开始前后端分离 [ vue + .netcore 补充教程 ] 二九║ Nuxt实战:异步实现数据双端渲染

    回顾 哈喽大家好!又是元气满满的周~~~二哈哈,不知道大家中秋节过的如何,马上又是国庆节了,博主我将通过三天的时间,给大家把项目二的数据添上(这里强调下,填充数据不是最重要的,最重要的是要配合着让大家 ...

随机推荐

  1. BZOJ3166 [Heoi2013]Alo 【可持久化trie树 + 二分 + ST表】

    题目 Welcome to ALO ( Arithmetic and Logistic Online).这是一个VR MMORPG , 如名字所见,到处充满了数学的谜题. 现在你拥有n颗宝石,每颗宝石 ...

  2. git 以及 工作区 版本库 暂存区

    https://www.jianshu.com/p/a308acded2ce            这个博客介绍的比较简单 https://blog.csdn.net/qq_31828515/arti ...

  3. mybatis 从数据库查询的信息不完整解决办法

    List<Product> products = productService.getProductListWithPage(productQuery); 今天碰到一个很奇怪的现象,上面的 ...

  4. [LeetCode] Letter Combinations of a Phone Number 回溯

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. 各种版本QT下载地址与VS2013+QT5.3.1环境搭建过程(转)

    原文转自 http://blog.csdn.net/baidu_34678439/article/details/54586058 1. 所有Qt版本下载地址: http://download.qt. ...

  6. 【Visual Studio - Dependency Walker】查找程序依赖的动态链接库文件(转)

    原文转自 http://163n.blog.163.com/blog/static/5603555220113151113287/ 有时我们需要知道一个程序依赖哪些动态链接库(DLL)文件.实际上,有 ...

  7. python进阶学习

    python高级用法 github: https://github.com/cq146637/Advanced     

  8. JavaScript闭包 循环输出i

    html <body> <p>产品一</p> <p>产品二</p> <p>产品三</p> <p>产品四& ...

  9. [开源] FreeSql AOP 功能模块

    前言 FreeSql 是一个功能强大的 .NETStandard 库,用于对象关系映射程序(O/RM),支持 .NETCore 2.1+ 或 .NETFramework 4.6.1+(QQ群:4336 ...

  10. 用NSLogger代替NSLog输出调试信息

    安装 NSLogger分为两部分,LoggerClient和NSLogger Viewer,你的App需要导入前者,后者是一个独立的mac应用,NSLogger所有的调试信息将输出到这个应用中. 安装 ...