模板引擎一般用作处理响应数据渲染,为了使用户界面与业务数据(内容)分离而产生的。
推荐一些模板引擎:
- artTemplate:https://aui.github.io/art-template/
- juicer:https://www.bootcdn.cn/juicer/
- doT:https://github.com/olado/doT
- handlebars:http://handlebarsjs.com/
- jsRender:https://www.jsviews.com/#jsrender
模板引擎实际上就是一个 API,模板引擎有很多种,使用方式大同小异,目的为了可以更容易的将数据渲染到 HTML中。
详情模板引擎语法去官网查看手册,上面例举一些模板引擎。
举例jsRender使用:
了解:
<html>
<head>
<title>jsRender模板引擎使用</title>
</head>
<body>
<table>
<thead>
<tr>
<th width="40"><input type="checkbox"></th>
<th>作者</th>
<th>评论</th>
<th>评论在</th>
<th>提交于</th>
<th>状态</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>
<!-- 第二步 -->
<script src="jquery.js"></script>
<!-- 第三步 -->
<script src="jsrender.min.js"></script>
<!-- 第五步 -->
<script id="comments_tmpl" type="text/x-jsrender">
// 循环数据集
{
{
for comments}}
// status,author,content,post_title,created是数据名字
// tr标签中还使用了模板引擎if语句,判断status不同的值采用不同的class样式
<tr {
{
if status == 'held'}} class="warning" {
{
else status =='rejected'}} class="danger" {
{
else}}{
{
/if}} data-id="{
{:id}}">
<td><input type="checkbox"></td>
<td>{
{
:author}}</td>
<td>{
{
:content}}</td>
<td>{
{
:post_title}}</td>
<td>{
{
:created}}</td>
<td>{
{
if status == 'held'}} 待审 {
{
else status =='rejected'}} 拒绝 {
{
else}} 同意 {
{
/if}}</td>
</tr>
{
{
/for}}
</script>
<!-- 第四步 -->
<script>
// 这里我是使用ajax请求后台php,返回JSON数据
$.getJSON('comments.php', {
}, function (res) {
// 为模板引擎绑定数据render()方法
var html = $('#comments_tmpl').render({
// comments是对应上一个script标签的for循环循环的对象(名字自己随意起),res是返回的JSON数据(这里不必大多关注)
comments: res
});
// 在页面添加展示数据
// 第六步
$('tbody').html(html);
});
});
</script>
程序员离职后收到原公司 2400 元,被告违反竞业协议赔 18 万!到底是怎么回事?
转载自:http://blog.sina.com.cn/s/blog_71715bf8010166qf.html开篇大话: Object-C语言的异常处理符号和C++、JAVA相似。再加上使用NSException,NSError或者自定义的类,你可以在你的应用程序里添加强大的错误处理机制。异常处理机制是由这个四个关键字支持的:@try,@catch,@thorw,@finally。当代码
问题一:node-sass npm ERR! command failed解决:1、删除 npm uninstall node-sass2、安装 npm install node-sass问题二:npm ERR! gyp info it worked if it ends with oknpm ERR! gyp info using [email protected] ERR! gyp info using [email protected] | win32 | x64npm ERR! gyp ERR!
Android 连接USB默认选中MTP模式需求分析Android系统默认连接USB会显示:正在通过USB为此设备充电,并且无法在电脑查看存储内容。需要实现的效果:Android 连接USB默认选中MTP模式,连接USB显示:正在通过USB传输文件,选择USB的使用方式的弹框下MTP模式为选中状态,并且可以在电脑端可以访问和写入存储空间。解决方案diff --git a/frameworks/base/services/usb/java/com/android/server/usb/UsbD
2012-11-05 作者: 出处:互联网 责编:联想Yoga分期付款月供279元五年前的11月5日,谷歌不仅宣布成立“开放手机联盟”(Open Handset Alliance),表示要帮助创建移动通信的开放标准,而且推出了Android平台——一个基于Linux的智能手机平台。以下是一篇简短的图文介绍,回顾了谷歌手机操作系统的发展。转
案例环境代码#include <stdio.h>int max(int x, int y){ return x > y ? x : y;}int main(){ int (* p)(int ,int) = & max; int a, b, c, d; printf("请输入三个整数:\n"); scanf("%...
代码范例clc,clear;T=0.001;k1=-1:T:5;f1=2*((k1>0)-(k1>4)); %f1(t)的 MATLAB描述k2=-1:T:3;f2=(k2>0)-(k2>2); %f2(t)信号的描述%画图程序subplot(3,1,1)plot(k1,f1);axis([-1,5,0,2.2]) %f1的显示范围title('f1');
很多朋友刚开始接触mysql数据库服务器,下面是网友整理的一篇mysql的安装教程,步骤明细也有详细的说明。MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版本。mysql 下载地址 http://www.jb51.net/softs/2193.html下面的是MySQL安装的图解,用的可执行文件安装的
题目来自于网络,答案是笔者整理的。仅供参考,欢迎指正来源: https://mp.weixin.qq.com/s?__biz=MzI1NDQ3MjQxNA==&amp;mid=2247485779&amp;idx=1&amp;sn=3b06b9923df7f40f887ead8b8a53e50e&amp;chksm=e9c5f0e2deb279f47fbfc3a12a70896bf95fa8c...
Add the content later...
一Homebrew安装git1.安装 Homebrew/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"2.安装gitbrew install git二xcode安装git1.在mac终端中直接输入git.提示是否安装开发者...
1.执行main方法时弹出 Error: A JNI error has occurred, please check your installation and try againe2.执行后控制台报的错误3.进入ClassLoader.java中,4.原因:在开始执行main方法时就已经加载了以java开头的包路径,所有类加载器在加载文件时会抛出异常5.解决方法:改包...