\n\n```","suggestedAnswer":[{"@type":"Answer","text":"The choice of the MIME type of the template(`text/x-jQuery-tmpl`) in the HTML code is chosen so that it is not recognized by the html parser of the browser so that it is not interpreted at execution."},{"@type":"Answer","text":"The choice of container for the template must be included in atag"},{"@type":"Answer","text":"Any variable to be provided by the template must be enclosed in braces preceded by the javascript symbol $. Example: ${title}"},{"@type":"Answer","text":"The proposed code is not functional, it contains inaccuracies."}],"acceptedAnswer":[{"@type":"Answer","text":"The choice of the MIME type of the template(`text/x-jQuery-tmpl`) in the HTML code is chosen so that it is not recognized by the html parser of the browser so that it is not interpreted at execution."},{"@type":"Answer","text":"Any variable to be provided by the template must be enclosed in braces preceded by the javascript symbol $. Example: ${title}"}]}}
Medium
Considering the following code used to define a template for an application, what can we say about this code?
<script id="bookTemplate" type="text/x-jQuery-tmpl">
<div>
<img src="BookPictures/${picture}"alt=""/>
<h2>${title}</h2>
price: ${formatPrice(price)}
</div>
</script>
<script type="text/javascript">
// Create an array of books
var books=[
{ title: 'ASP.NET 4 Unleashed', price: 37.79, picture: 'AspNet4Unleashed.jpg' },
{ title: 'ASP.NET MVC Unleashed', price: 44.99, picture: 'AspNetMvcUnleashed.jpg' },
{ title: 'ASP.NET KickStart', price: 4.0, picture: 'AspNetkickStart.jpg' },
{ title: 'ASP.NET MVC Unleashed iPhone', price: 44.99, picture: 'AspNetMvcUnleashedIPhone.jpg' }
];
// Display the books using the template
$('#bookTemplate').tmpl(books).appendTo('#bookContainer');
function formatPrice(price){
return '$'+ price.toFixed(2);
}
</script>
Author: InconnuStatus: PublishedQuestion passed 274 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!
0
Select the first 5 elements in a list using jQuery0
jQuery event handling methods: `trigger()`, `bind()`, `triggerHandler()`, `.on()`1
We want to develop a jQuery plug-in or simply define our own methods or properties on the object by augmentation. Which of these statements are correct?1
Which of these different propositions are correct regarding AJAX processing in jQuery?0
Select an h1 element of class CSS blue having a div element in its parentage in jQuery1
Implement a multi-selection behavior on a list of checkboxes in a form using jQuery.0
How to bind a click event to a div, p and b elements in jQuery.