Created
June 8, 2018 22:04
-
-
Save TravisMullen/2c4f465bde64fcc88df4538a9608cb55 to your computer and use it in GitHub Desktop.
Example: Lit Element's Repeat Method
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
<html> | |
<head> | |
<!-- Polyfills only needed for Firefox and Edge. --> | |
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@next/webcomponents-loader.js"></script> | |
</head> | |
<body> | |
<!-- Works only on browsers that support Javascript modules like | |
Chrome, Safari, Firefox 60, Edge 17 --> | |
<script type="module"> | |
import { LitElement, html } from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module'; | |
import { repeat } from 'https://unpkg.com/lit-html@latest/lib/repeat.js?module'; | |
class ListJawn extends LitElement { | |
static get properties() { | |
return { | |
collection: Array | |
} | |
} | |
constructor() { | |
super(); | |
this.collection = [ | |
{ color: 'yellow', name: 'Saturn', order: 2, target: '#Saturn' }, | |
{ color: 'green', name: 'Jupiter', order: 3, target: '#Jupiter' } | |
]; | |
} | |
_render({ collection }) { | |
return html` | |
<ul> | |
${repeat( | |
collection, | |
(item, index) => html`<li>${item.name}</li>` | |
)} | |
</ul> | |
` | |
} | |
} | |
customElements.define('my-list', ListJawn); | |
</script> | |
<my-list></my-list> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment