Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's very easy to use Client side + Server side templating.When we are building some web apps,we should use ajax to get some data and use the callback function to deal with it.So we should render these data on the client side.</p> <p>The question is how to render them on client side?</p> <p>Now We just need a client side jade.js.</p> <p>Follow this document : <a href="https://github.com/visionmedia/jade#readme" rel="nofollow">https://github.com/visionmedia/jade#readme</a></p> <p><strong>First</strong></p> <pre><code>git clone https://github.com/visionmedia/jade.git </code></pre> <p><strong>Second</strong> </p> <pre><code>$ make jade.js ( in fact the project has already compile the file for us ) so we just need to copy this file to the path that we use. </code></pre> <p><strong>Third</strong></p> <pre><code>read my demo below : &lt;script type='text/javascript' language='javascript' src="lib/jquery-1.8.2.min.js"&gt;&lt;/script&gt; &lt;script type='text/javascript' language='javascript' src="lib/jade/jade.js"&gt;&lt;/script&gt; &lt;script type='template' id='test'&gt; ul li hello world li #{item} li #{item} li #{item} &lt;/script&gt; &lt;script&gt; var compileText = $("#test").text(); console.log( typeof( compileText ) ); var fn = jade.compile( compileText , { layout : false } ); var out = fn( {item : "this is item " } ); console.log( out ); $("body").append( out ); &lt;/script&gt; </code></pre> <p>Now you can see the output result in the body</p> <pre><code>hello world this is item this is item this is item </code></pre> <p>After reading this demo I think that you would know how to seperate jade server side and client side.If you can understand which one compile the jade template,then all the questions are easy.</p> <p>Maybe you would have another question now.How to write some jade template codes in *.jade?The document also provide us a way to do it.This Tutorial may help you.</p> <p>index.jade</p> <pre><code>!!!5 html head title hello world body ul#list script#list-template(type='template') |- for( var i in data ) | li(class='list') \#{ data[i].name } |- } </code></pre> <p>index.js</p> <pre><code>/* you javascript code */ var compileText = $('#list-template').text(); var compile = jade.compile( compileText , { layout : false } ); var data = [{ "name" : "Ben" } , {"name" : "Jack" } , {"name" : "Rose" }]; var outputText = compile( data ); $("#list").append( outputText ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload