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>
相關文章
相關標籤/搜索