Skip to content

Instantly share code, notes, and snippets.

@teaplanet
Created December 23, 2014 11:33
Show Gist options
  • Select an option

  • Save teaplanet/f2b165e598db8d86658d to your computer and use it in GitHub Desktop.

Select an option

Save teaplanet/f2b165e598db8d86658d to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 2-3
<!-- http://learn.ractivejs.org/nested-properties/3 -->
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<div id='container'></div>
<script id='template' type='text/ractive'>
<h2>Country profile</h2>
{{#with country}}
<p>{{name}} is a {{climate.temperature}} country with {{climate.rainfall}} rainfall and a population of {{population}}.</p>
{{#with capital}}
<p>The capital city is {{name}} (<a href='https://maps.google.co.uk/maps/place/{{name}}/@{{lat}},{{lon}},12z' target='_blank'>see map</a>).</p>
{{/with}}
{{/with}}
{{#country}}
'#' instead of 'with'.
{{/country}}
</script>
var ractive = new Ractive({
el: 'container',
template: '#template',
data: {
country: {
name: 'The UK',
climate: { temperature: 'cold', rainfall: 'excessive' },
population: 63230000,
capital: { name: 'London', lat: 51.5171, lon: -0.1062 }
}
}
});
var country = ractive.get('country');
country.climate.rainfall = 'very high';
ractive.update('country');
// same as...
//ractive.set('country.climate.rainfall', 'very high');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment