RIOT.JS Tutorial
Selected Reading
- RIOT.JS - Discussion
- RIOT.JS - Useful Resources
- RIOT.JS - Quick Guide
- RIOT.JS - Observables
- RIOT.JS - Mixin
- RIOT.JS - Loops
- RIOT.JS - Accessing DOM
- RIOT.JS - Event Handling
- RIOT.JS - Yield
- RIOT.JS - Conditional
- RIOT.JS - Styling
- RIOT.JS - Expressions
- RIOT.JS - Tags
- RIOT.JS - First Application
- RIOT.JS - Environment Setup
- RIOT.JS - Overview
- RIOT.JS - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
RIOT.JS - Loops
RIOT.JS - Loops
We can iterate through RIOT array of primitives or of Objects and create/update the html elements on the go. Using "each" construct we can achieve it.
Create array − Create an array of object.
this.cities = [ { city : "Shanghai" , country:"China" , done: true }, { city : "Seoul" , country:"South Korea" }, { city : "Moscow" , country:"Russia" } ];
Add each attribute − Now use the "each" attribute.
<ul> <p each = { cities } ></p> </ul>
Iterate array of objects − Iterate the array using object properties.
<input type = "checkbox" checked = { done }> { city } - { country }
Example
Following is the complete example.
custom7Tag.tag
<custom7Tag> <style> ul { pst-style-type: none; } </style> <ul> <p each = { cities } > <input type = "checkbox" checked = { done }> { city } - { country } </p> </ul> <script> this.cities = [ { city : "Shanghai" , country:"China" , done: true }, { city : "Seoul" , country:"South Korea" }, { city : "Moscow" , country:"Russia" } ]; </script> </custom7Tag>
custom7.htm
<html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/pbs/riot/3.13.2/riot+compiler.min.js"></script> </head> <body> <custom7Tag></custom6Tag> <script src = "custom7Tag.tag" type = "riot/tag"></script> <script> riot.mount("custom7Tag"); </script> </body> </html>
This will produce following result −
Advertisements