Created
December 23, 2014 11:33
-
-
Save teaplanet/f2b165e598db8d86658d to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 2-3
This file contains hidden or 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/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> |
This file contains hidden or 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 = 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