Last active
June 21, 2017 17:24
-
-
Save montrealist/0ffbca80fe0475f97a6aa67bd86c9040 to your computer and use it in GitHub Desktop.
Nesting Polymer elements and dynamic content inside dom-repeat (source: http://jsbin.com/gagojas)
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="nesting Polymer elements and dynamic content inside dom-repeat"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<base href="http://polygit.org/polymer+:1.x/components/" /> | |
<link href="polymer/polymer.html" rel="import" /> | |
</head> | |
<body> | |
<dom-module id="ddc-tabs"> | |
<template> | |
<ul class="links"> | |
<template is="dom-repeat" items="[[items]]"> | |
<li><a href="#">show [[item.content]]</a></li> | |
</template> | |
</ul> | |
<ul class="sections"> | |
<template is="dom-repeat" items="[[items]]"> | |
<li><ddc-grid-selector regions="[[items]]">[[item.content]]</ddc-grid-selector></li> | |
</template> | |
</ul> | |
</template> | |
<script> | |
Polymer({ | |
is: 'ddc-tabs', | |
properties: { | |
items: Array, | |
}, | |
}); | |
</script> | |
</dom-module> | |
<dom-module id="ddc-grid-selector"> | |
<template> | |
<section> | |
<content></content> | |
</section> | |
</template> | |
<script> | |
Polymer({ | |
is: 'ddc-grid-selector', | |
properties: { | |
regions: { | |
type: Array, | |
notify: true, | |
observer: '_onRegionsLoad' | |
} | |
}, | |
_onRegionsLoad: function(newv, oldv) { | |
console.log('_onRegionsLoad fired', newv, oldv); | |
} | |
}); | |
</script> | |
</dom-module> | |
<dom-module is="ddc-region-selector"> | |
<template> | |
<ddc-tabs items="[[myItems]]"></ddc-tabs> | |
<button on-tap="_onButtonClick">add new one</button> | |
</template> | |
<script> | |
Polymer({ | |
is: 'ddc-region-selector', | |
ready: function() { | |
this.myItems = [ | |
{ content: "First tab" }, | |
{ content: "Second tab" }, | |
{ content: "Third tab" }, | |
]; | |
}, | |
_onButtonClick: function(){ | |
this.push('myItems', { content: 'another tab' }); | |
} | |
}); | |
</script> | |
</dom-module> | |
<ddc-region-selector></ddc-region-selector> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From here: https://stackoverflow.com/questions/44504405/nesting-elements-and-dynamic-content-inside-dom-repeat-polymer-1-0