ForgejComponent
en

jComponent

Render lists with a ui-bind template

jComponent 20 · jcomponent@20 jcomponentfrontendbindingtemplates Executed with jComponent 20

With the template command, <ui-bind> renders a Tangular template instead of setting one value. The template is the <script type="text/html"> inside the element; value is the data of the path. Every time the path changes the element is rendered again, so lists stay in sync with the state.

public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<ui-bind path="products" config="template">
		<script type="text/html">
			<ul>
			{{ foreach p in value }}
				<li class="product">{{ p.name }} - {{ p.price }}</li>
			{{ end }}
			</ul>
		</script>
	</ui-bind>

	<script>
		SET('products', [{ name: 'Book', price: 12 }, { name: 'Pen', price: 3 }]);
	</script>

</body>
</html>
Try it in your browser

Edit the example and run it. It runs in an isolated frame in your browser; nothing is sent to our server.

Preview