Last active
August 29, 2015 14:12
-
-
Save teaplanet/3581db7798a1e6da4eba to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 6-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- http://learn.ractivejs.org/list-sections/3 --> | |
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script> | |
<div id='container'></div> | |
<script id='template' type='text/ractive'> | |
<table class='superheroes'> | |
<tr> | |
<th>#</th> | |
<th>Superhero name</th> | |
<th>Real name</th> | |
<th>Superpower</th> | |
</tr> | |
{{#each superheroes:num}} | |
<tr> | |
<td>{{num+1}}</td> | |
<td><a href='{{info}}'>{{name}}</a></td> | |
<td>{{realname}}</td> | |
<td>{{power}}</td> | |
</tr> | |
{{/each}} | |
</table> | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var ractive, xmen; | |
var xmen = [ | |
{ name: 'Nightcrawler', realname: 'Wagner, Kurt', power: 'Teleportation', info: 'http://www.superherodb.com/Nightcrawler/10-107/' }, | |
{ name: 'Cyclops', realname: 'Summers, Scott', power: 'Optic blast', info: 'http://www.superherodb.com/Cyclops/10-50/' }, | |
{ name: 'Rogue', realname: 'Marie, Anna', power: 'Absorbing powers', info: 'http://www.superherodb.com/Rogue/10-831/' }, | |
{ name: 'Wolverine', realname: 'Howlett, James', power: 'Regeneration', info: 'http://www.superherodb.com/Wolverine/10-161/' } | |
]; | |
var ractive = new Ractive({ | |
el: 'container', | |
template: '#template', | |
data: { superheroes: xmen } | |
}); | |
var newSuperhero = { | |
name: 'Storm', | |
realname: 'Monroe, Ororo', | |
power: 'Controlling the weather', | |
info: 'http://www.superherodb.com/Storm/10-135/' | |
}; | |
xmen.push(newSuperhero); | |
var index = ractive.get('superheroes').length; | |
ractive.set('superheroes[' + index + ']', newSuperhero); | |
//xmen.reverse(); | |
//xmen.shift(); | |
//xmen.pop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment