Home
Run

Demo: Render template against remote data



HTML:

<script id="movieTemplate" type="text/x-jquery-tmpl">
	<li>
		<b>${Name}</b> (${ReleaseYear})
	</li>
</script>

<ul id="movieList"></ul>

Script:

$.ajax({

	dataType: "jsonp",

	url: "http://odata.netflix.com/Catalog/Genres('" + genre
		+ "')/Titles?$format=json&$skip="
		+ skip + "&$top=" + top,

	jsonp: "$callback",

	success: function( data ) {
			var movies = data.d;				 // Get the movies array from the data

			$( "#movieList" ).empty();			 // Remove current set of movie template items

			$( "#movieTemplate" ).tmpl( movies ) // Render the template with the movies data
				.appendTo( "#movieList" );		 // and insert the rendered HTML under the "movieList" element
	}
});