Created
November 27, 2019 01:12
-
-
Save leotada/42255a7c65d0558e2ff21d7d0727a5a3 to your computer and use it in GitHub Desktop.
Templating components with JQuery
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
| class TextComponent { | |
| static template () { | |
| return `<button type="button"> | |
| StaticText | |
| </button>` | |
| } | |
| app.components = { | |
| 'text-component': TextComponent, | |
| }; | |
| // templating components | |
| for (let componentName in app.components) { | |
| let componentList = $.find(componentName); // $.find('text-component') | |
| for (let component of componentList) { | |
| component = $(component); | |
| component.parent().append(app.components[componentName].template()); | |
| component.remove(); | |
| } | |
| } |
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
| <li> | |
| <text-component></text-component> | |
| <text-component></text-component> | |
| </li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment