Last active
August 29, 2015 14:12
-
-
Save teaplanet/c6d5c772db0ce36c1b58 to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 3-2
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/expressions/2 --> | |
| <script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script> | |
| <div id='container'></div> | |
| <script id='template' type='text/ractive'> | |
| <table> | |
| <tr> | |
| <th>Price per {{item}}</th> | |
| <th>Quantity</th> | |
| <th>Total</th> | |
| </tr> | |
| <tr> | |
| <td>{{ format(price) }}</td> | |
| <td>{{ quantity }}</td> | |
| <td>{{ format(price * quantity) }}</td> | |
| </tr> | |
| </table> | |
| </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: { | |
| item: 'pint of milk', | |
| price: 0.49, | |
| quantity: 5, | |
| format: function(num) { | |
| if (num < 1) { | |
| return (100 * num) + 'p'; | |
| } | |
| return '£' + num.toFixed(2); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment