Including Javascript in Jquery templates
Is it possible to perform javscript operations within the jQuery template markup?
I have a collection of objects for which I only want to show certain information on the first iteration through the template.
<script type="text/javascript">
var x = 0; // Counter
</script>
<script id="QuoteTemplate" type="text/x-jQuery-tmpl">
{{if x = 0 }}
// Sh开发者_JS百科ow Stuff
{{ x++ }}
</script>
JQuery template itself is any HTML markup, along with any of a set of template tags which enable some very rich scenarios for creating data-driven UI. The current set of tags that are supported in jQuery templates are:
- ${...}: Evaluate fields or expression
- {{each ...}}...{{/each}}: Iterate without creating template items
- {{if ...}}...{{else ...}}...{{/if}}: Conditional sections
- {{html ...}}: Insert markup from data
- {{tmpl ...}}: Composition, as template items
- {{wrap ...}}...{{/wrap}}: Composition, plus incorporation of wrapped HTML
And for more details and example please visit here.
I don't think it a bad question. The doc is clear but you have to find it on the ${} syntax.
${fieldNameOrExpression} The name of a field on the current data item, or a JavaScript function or expression to be evaluated.
Try $.tmpl('<p>${a + 1}</p>', {a: 1})
in a console.
精彩评论