Skip to content

Instantly share code, notes, and snippets.

@Stuk
Forked from kriskowal/README.md
Last active December 12, 2015 08:58
Show Gist options
  • Save Stuk/4747664 to your computer and use it in GitHub Desktop.
Save Stuk/4747664 to your computer and use it in GitHub Desktop.
{
"name": "montage-1116",
"version": "0.0.0",
"dependencies": {
"montage": "~0.12.3"
}
}
<!-- /repeat.html -->
<!DOCTYPE html>
<html>
<head>
<title>Hello Montage</title>
<script type="text/javascript" src="node_modules/montage/montage.js" data-auto-package></script>
<script type="text/montage-serialization">
{
"repeat": {
"prototype": "repeat",
"properties": {
"element": {"#": "component"}
}
},
"changeButton": {
"prototype": "montage/ui/button.reel",
"properties": {
"element": {"#": "button"},
"label": "Change Content"
},
"listeners": [
{
"type": "action",
"listener": {"@": "repeat"}
}
]
},
"repetition": {
"prototype": "montage/ui/repetition.reel",
"properties": {
"element": {"#": "repetition"}
},
"bindings": {
"contentController": {"<-": "@repeat.arrayController"}
}
},
"value": {
"prototype": "montage/ui/dynamic-text.reel",
"properties": {
"element": {"#": "value"}
},
"bindings": {
"value": {"<-": "@repetition.objectAtCurrentIteration"}
}
}
}
</script>
</head>
<body>
<div data-montage-id="component">
<button data-montage-id="button"></button>
<ul data-montage-id="repetition">
<li data-montage-id="value"></li>
</ul>
</div>
</body>
</html>
// owner.js
var Montage = require("montage").Montage,
Component = require("montage/ui/component").Component,
ArrayController = require("montage/ui/controller/array-controller").ArrayController;
exports.Repeat = Montage.create(Montage, {
arrayController: {
value: null
},
didCreate: {
value: function () {
var content = ["a", "b", "c"];
this.arrayController = ArrayController.create().initWithContent(content);
}
},
handleChangeButtonAction: {
value: function (evt) {
var newContentCount = Math.floor(Math.random() * 11),
newContent = [],
i;
for (i = 0; i < newContentCount; i++) {
newContent.push(Math.random());
}
this.arrayController.content = newContent;
console.log(newContent);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment