Skip to content

Instantly share code, notes, and snippets.

@darkcolonist
Created February 17, 2016 06:12
Show Gist options
  • Save darkcolonist/d6352f649e89fc9fd091 to your computer and use it in GitHub Desktop.
Save darkcolonist/d6352f649e89fc9fd091 to your computer and use it in GitHub Desktop.
ractive.js sample implementation
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Ractive Test</title>
</head>
<body>
<h1>Ractive Test</h1>
<div id="container">
</div>
<script id="template" type="text/html">
<table>
<tr>
<th>#</th>
<th>Name</th>
<th>Gender</th>
</tr>
{{#each people:num}}
<tr>
<td>{{num+1}}</td>
<td>{{name}}</td>
<td>{{gender}}</td>
</tr>
{{/each}}
</table>
</script>
<script src='http://cdn.ractivejs.org/0.7.3/ractive.js'></script>
<script>
var listOfPersons = []
var personsTable = new Ractive({
// The `el` option can be a node, an ID, or a CSS selector.
el: '#container',
// We could pass in a string, but for the sake of convenience
// we're passing the ID of the <script> tag above.
template: '#template',
// Here, we're passing in some initial data
data: {
people: listOfPersons
}
})
listOfPersons.push({name:"Cris",gender:"male"})
listOfPersons.push({name:"John",gender:"male"})
listOfPersons.push({name:"Doe",gender:"male"})
listOfPersons[2].name = "Jane"
listOfPersons[2].gender = "female"
personsTable.update("people")
</script>
</body>
</html>
@darkcolonist
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment