Array
_.chunk
_.compact
_.concat
_.difference
_.differenceBy
_.differenceWith
_.drop
_.dropRight
_.dropRightWhile
_.dropWhile
_.fill
_.findIndex
_.findLastIndex
_.flatten
_.flattenDeep
_.flattenDepth
_.fromPairs
_.head
_.indexOf
_.initial
_.intersection
_.intersectionBy
_.intersectionWith
_.join
_.last
_.lastIndexOf
_.nth
_.pull
_.pullAll
_.pullAllBy
_.pullAllWith
Collection
Date
Function
Lang
_.castArray
_.clone
_.cloneDeep
_.cloneDeepWith
_.cloneWith
_.conformsTo
_.eq
_.gt
_.gte
_.isArguments
_.isArray
_.isArrayBuffer
_.isArrayLike
_.isArrayLikeObject
_.isBoolean
_.isBuffer
_.isDate
_.isElement
_.isEmpty
_.isEqual
_.isEqualWith
_.isError
_.isFinite
_.isFunction
_.isInteger
_.isLength
_.isMap
_.isMatch
_.isMatchWith
_.isNaN
_.isNative
_.isNil
_.isNull
_.isNumber
Math
Object
Seq
String
_.camelCase
_.capitalize
_.deburr
_.endsWith
_.escape
_.escapeRegExp
_.kebabCase
_.lowerCase
_.lowerFirst
_.pad
_.padEnd
_.padStart(string ='',length = 0,chars ='')
_.parseInt
_.repeat(string ='',n = 1)
_.replace(string ='',pattern,replacement)
_.snakeCase
_.split
_.startCase
_.startsWith
_.template
_.toLower
_.toUpper
_.trim
_.trimEnd(string ='',chars = whitespace)
_.trimStart
_.truncate
_.unescape
_.upperCase
_.upperFirst
Util
_.attempt
_.bindAll
_.cond
_.conforms
_.constant
_.defaultTo
_.flow
_.flowRight
_.identity
_.iteratee
_.matches
_.matchesProperty
_.method
_.methodOf
_.mixin
_.noConflict
_.noop
_.nthArg
_.over
_.overEvery
_.overSome
_.property
_.propertyOf
_.range
_.rangeRight
_.runInContext
_.stubArray()
_.stubFalse
_.stubObject
_.stubString
_.stubTrue
_.times
_.toPath
_.uniqueId
Methods
创建一个编译的模板函数,可以在“插入”分隔符中插入数据属性,在“转义”分隔符中插入HTML转义插值数据属性,并在“评估”分隔符中执行JavaScript。数据属性可以作为模板中的自由变量来访问。如果给定设置对象,则优先于 _.templateSettings
值。
注意:在开发版本中,_.template
利用sourceURL来更容易地进行调试。
有关预编译模板的更多信息,请参阅lodash的自定义构建文档。
有关Chrome扩展程序沙箱的更多信息,请参阅Chrome的扩展程序文档。
0.1.0
[string='']
(string): The template string. [options={}]
(Object): The options object. [options.escape=_.templateSettings.escape]
(RegExp): The HTML "escape" delimiter. [options.evaluate=_.templateSettings.evaluate]
(RegExp): The "evaluate" delimiter. [options.imports=_.templateSettings.imports]
(Object): An object to import into the template as free variables. [options.interpolate=_.templateSettings.interpolate]
(RegExp): The "interpolate" delimiter. [options.sourceURL='lodash.templateSources[n]']
(string): The sourceURL of the compiled template. [options.variable='obj']
(string): The data object variable name. (功能):返回已编译的模板功能。
// Use the "interpolate" delimiter to create a compiled template. var compiled = _.template('hello <%= user %>!'); compiled({ 'user': 'fred' }); // => 'hello fred!' // Use the HTML "escape" delimiter to escape data property values. var compiled = _.template('<b><%- value %></b>'); compiled({ 'value': '<script>' }); // => '<b>&lt;script&gt;</b>' // Use the "evaluate" delimiter to execute JavaScript and generate HTML. var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); compiled({ 'users': ['fred', 'barney'] }); // => '<li>fred</li><li>barney</li>' // Use the internal `print` function in "evaluate" delimiters. var compiled = _.template('<% print("hello " + user); %>!'); compiled({ 'user': 'barney' }); // => 'hello barney!' // Use the ES template literal delimiter as an "interpolate" delimiter. // Disable support by replacing the "interpolate" delimiter. var compiled = _.template('hello ${ user }!'); compiled({ 'user': 'pebbles' }); // => 'hello pebbles!' // Use backslashes to treat delimiters as plain text. var compiled = _.template('<%= "\\<%- value %\\>" %>'); compiled({ 'value': 'ignored' }); // => '<%- value %>' // Use the `imports` option to import `jQuery` as `jq`. var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); compiled({ 'users': ['fred', 'barney'] }); // => '<li>fred</li><li>barney</li>' // Use the `sourceURL` option to specify a custom sourceURL for the template. var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); compiled(data); // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. // Use the `variable` option to ensure a with-statement isn't used in the compiled template. var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); compiled.source; // => function(data) { // var __t, __p = ''; // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; // return __p; // } // Use custom template delimiters. _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; var compiled = _.template('hello {{ user }}!'); compiled({ 'user': 'mustache' }); // => 'hello mustache!' // Use the `source` property to inline compiled templates for meaningful // line numbers in error messages and stack traces. fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\ var JST = {\ "main": ' + _.template(mainText).source + '\ };\ ');