我想用如下。如何在jsRender中使用javascript變量?
<script id="movieTemplate" type="text/x-jquery-tmpl">
<tr>
<td>{{=Title}}</td>
<td>
{{* var title = $ctx.GetTitleFunction($view);}}
{{#each Languages}}
<div>
<em>{{=Name}}</em>
<em>({{* title;}})</em>
</div>
{{/each}}
</td>
</tr>
</script>
<script type="text/javascript">
function GetTitle(data){
return "Title : " + data.Title;
}
var movies = [
{
Title: "Meet Joe Black",
Languages: [
{ Name: "English" },
{ Name: "French" }
]
},
{
Title: "Eyes Wide Shut",
Languages: [
{ Name: "French" },
{ Name: "Mandarin" },
{ Name: "Spanish" }
]
}
];
$.views.allowCode = true;
$.views.registerHelpers({ GetTitleFunction: GetTitle });
$("#movieList").html(
$("#movieTemplate").render(movies)
);
</script>
我無法使用{{* title;}}或{{* = title}}來呈現JavaScript變量。
如何在JavaScript變量中呈現值?
我可以通過使用{{* result = result + title}}來呈現JavaScript變量或函數的返回值。 – Ant 2012-02-14 03:08:02