mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Merge branch 'master' of github.com:documentcloud/underscore
This commit is contained in:
26
index.html
26
index.html
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<title>Underscore.js</title>
|
||||
<style>
|
||||
body {
|
||||
@@ -1335,7 +1335,7 @@ _.result(object, 'stuff');
|
||||
=> "nonsense"</pre>
|
||||
|
||||
<p id="template">
|
||||
<b class="header">template</b><code>_.template(templateString, [context])</code>
|
||||
<b class="header">template</b><code>_.template(templateString, [data], [settings])</code>
|
||||
<br />
|
||||
Compiles JavaScript templates into functions that can be evaluated
|
||||
for rendering. Useful for rendering complicated bits of HTML from JSON
|
||||
@@ -1343,11 +1343,13 @@ _.result(object, 'stuff');
|
||||
<tt><%= … %></tt>, as well as execute arbitrary JavaScript code, with
|
||||
<tt><% … %></tt>. If you wish to interpolate a value, and have
|
||||
it be HTML-escaped, use <tt><%- … %></tt> When you evaluate a template function, pass in a
|
||||
<b>context</b> object that has properties corresponding to the template's free
|
||||
variables. If you're writing a one-off, you can pass the <b>context</b>
|
||||
<b>data</b> object that has properties corresponding to the template's free
|
||||
variables. If you're writing a one-off, you can pass the <b>data</b>
|
||||
object as the second parameter to <b>template</b> in order to render
|
||||
immediately instead of returning a template function.
|
||||
immediately instead of returning a template function. The <b>settings</b> argument
|
||||
should be a hash containing any <tt>_.templateSettings</tt> that should be overriden.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var compiled = _.template("hello: <%= name %>");
|
||||
compiled({name : 'moe'});
|
||||
@@ -1393,6 +1395,16 @@ var template = _.template("Hello {{ name }}!");
|
||||
template({name : "Mustache"});
|
||||
=> "Hello Mustache!"</pre>
|
||||
|
||||
<p>
|
||||
By default, <b>template</b> places the values from your data in the local scope
|
||||
via the <tt>with</tt> statement. However, you can specify a single variable name
|
||||
with the <b>variable</b> setting.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
_.template("<%= data.hasWith %>", {hasWith: 'no'}, {variable: 'data'});
|
||||
=> "no"</pre>
|
||||
|
||||
<p>
|
||||
Precompiling your templates can be a big help when debugging errors you can't
|
||||
reproduce. This is because precompiled templates can provide line numbers and
|
||||
@@ -1570,8 +1582,8 @@ _([1, 2, 3]).value();
|
||||
<b class="header">1.2.4</b> — <small><i>Jan. 4, 2012</i></small><br />
|
||||
<ul>
|
||||
<li>
|
||||
You now can (and probably should, as it's simpler)
|
||||
write <tt>_.chain(list)</tt>
|
||||
You now can (and probably should, as it's simpler)
|
||||
write <tt>_.chain(list)</tt>
|
||||
instead of <tt>_(list).chain()</tt>.
|
||||
</li>
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user