mustache .js 条件判断

JavaScript010

mustache .js 条件判断,第1张

先要把json字符串转换成对象

var persons = json.parse(json)// json就是你贴出来的东西然后包装成要传入的数据对象

var data = {persons: persons}然后渲染模版

var html = mustache.render(template, data)// 其中template为html模版html模版里这么写,来循环输出json数据

{{#persons}}

{{name}}

{{/persons}}

SPM v.1.1.2 With SeaJS

SPM v1.1.2使用指南

1.SPM用途

SeaJS提供了模块化开发的机制,在代码开发完后,还需要做产品发布相关的一些操作。 这些可以通过SPM来完成,SPM提供了模块安装、压缩、打包部署等功能。

2.SPM安装

1.从nodejs官网下载最新版本的node。 这里以node-0.8.14为例,直接下载windows版本的安装包即可,默认安装到"C:\Program Files\nodejs", 会自动添加到path中,查看一下版本。

C:\Documents and Settings\Administratornode -v

v0.8.14

2.新版的node都带了npm,这里通过npm来安装spm。下面指定安装1.1.2版本,在当前为最新版本。 如果不指定版本号,默认安装最新版本。安装包大小为11.8M,根据网速不同,请耐心等待。

C:\Documents and Settings\Administratornpm install [email protected] -g

npm http GET https://registry.npmjs.org/spm/1.1.2

npm http 200 https://registry.npmjs.org/spm/1.1.2

npm http GET https://registry.npmjs.org/spm/-/spm-1.1.2.tgz

npm http 200 https://registry.npmjs.org/spm/-/spm-1.1.2.tgz

npm http GET https://registry.npmjs.org/spm-env

npm http GET https://registry.npmjs.org/csslint

npm http GET https://registry.npmjs.org/async

...

下载完spm后,会根据压缩包中的package.json自动安装相关的依赖包,最后会显示如下的界面。

C:\Documents and Settings\Administrator\Application Data\npm\spm - C:\Documents and Settings\Administrator\Application

Data\npm\node_modules\spm\bin\spm

[email protected] C:\Documents and Settings\Administrator\Application Data\npm\node_modules\spm

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected] ([email protected])

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected]

├── [email protected] ([email protected])

├── [email protected] ([email protected], [email protected], [email protected])

├── [email protected] ([email protected])

├── [email protected]

├── [email protected] ([email protected], [email protected])

├── [email protected] ([email protected])

├── [email protected] ([email protected], [email protected])

├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])

└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected].

0, [email protected], [email protected], [email protected])

3.安装后检查一下版本

C:\Documents and Settings\Administratorspm -v

v1.1.2

如果这种方式安装比较慢,可以git 源码后安装,详见官方文档。

本次测试使用的是Widnows XP操作系统

以下演示使用的是v1.1.2版本,不同的版本可能存在差异,请自行留意。

3.SPM查找和安装模块

我们先在C盘根目录建立一个assets目录,用于保存前端开发的所有文件。

先使用spm下载开发需要的模块,spm默认的模块服务器为http://modules.spmjs.org/。 也可以自己在内网搭搭设一个模块服务器,这里不详述。

我们可以先使用spm search命令在模块服务器查找可安装的模块的版本。

C:\assetsspm search seajs

C:\assetsspm search jquery

C:\assetsspm search mustache //以mustache为例子

...

versions://这里列出可用的版本

0.4.0:

- mustache.js

0.5.0:

- mustache.js

root: gallery //显示模块的跟目录

name: mustache

tag:

type:

C:\assetsspm install [email protected] //指定安装seajs版本

C:\assetsspm install gallery.jquery //不指定版本号,默认安装服务器上jquery最新版本

C:\assetsspm install gallery.mustache //不指定版本号,默认安装服务器上mustache最新版

有的。使用过Mustache , Hogan.js,或者handlerbars的话,你就可以快速的理解AngularJS的模板引擎语法,应为它是纯HTML的。AngularJS通过DOM浏览来完成此类功能,使用上面提到的directives。模板被作为DOM元素传递到Angular的编译器中,可以被...