Created
April 6, 2018 12:13
-
-
Save yosevu/30e4eee843c69d8d75a4a1b7a77dc681 to your computer and use it in GitHub Desktop.
Hot Dog Stand in Browser: renderOptions()
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
| // Before | |
| this.renderOptions(item, name, this.menuItems[name]); | |
| renderOptions(item, name, { options, required, onlyOne }) { | |
| options.forEach((option, i) => { | |
| item.innerHTML += ` | |
| <label class="option" for="${option}"> | |
| <input | |
| id="${option}" | |
| name="${name}" | |
| ${required} | |
| type=${onlyOne ? 'radio' : 'checkbox'} | |
| value="${option}" | |
| > | |
| ${option} | |
| </label> | |
| `; | |
| }); | |
| } | |
| // After | |
| item.innerHTML += this.renderOptions(name, this.menuItems[name]).join(''); | |
| renderOptions(name, { options, required, onlyOne }) { | |
| return options.map((option, i) => (` | |
| <label class="option" for="${option}"> | |
| <input | |
| id="${option}" | |
| name="${name}" | |
| ${required} | |
| type=${onlyOne ? 'radio' : 'checkbox'} | |
| value="${option}" | |
| > | |
| ${option} | |
| </label> | |
| `) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment