underscore的使用

一、连接html

  npm underscore:https://www.npmjs.com/package/underscorenpm

  官网:https://underscorejs.org/函数

 

二、npm安装:npm install underscoreui

三、简单使用spa

var _ = require("underscore"); var array = _.map([1, 2, 3], (x) => x * x); console.log(array); // [ 1, 4, 9 ]

var array2 = _.map(["A", "B", "C"], (x) => x.toLowerCase()); console.log(array2); //[ 'a', 'b', 'c' ]

// template():声明模板数据
var fn = _.template("<h2>hello, I am <%= name %>!</h2>"); // template()函数的返回值类型为函数
var html = fn({name: 'hanmeimei'}); console.log(html); // <h2>hello, I am hanmeimei!</h2>
相关文章
相关标签/搜索