Created
April 4, 2017 23:02
-
-
Save djedi/f40b6094108860ee8f98789239e8aaef to your computer and use it in GitHub Desktop.
Array of object observer
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
<template> | |
<table> | |
<thead> | |
<tr> | |
<th>id</th> | |
<th>Title</th> | |
<th>Updated</th> | |
<th>Status</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr repeat.for="row of data"> | |
<td>${row.id}</td> | |
<td>${row.title}</td> | |
<td>${row.updated}</td> | |
<td>${row.status}</td> | |
</tr> | |
</tbody> | |
</table> | |
</template> |
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
export class App { | |
data = []; | |
constructor() { | |
this.data.push(new Row(1)); | |
this.data.push(new Row(2, 'Test')); | |
} | |
attached() { | |
this.interval = setInterval(() => { | |
const max = this.data.length - 1; | |
const min = 0; | |
const randomIndex = Math.floor(Math.random() * (max - min + 1)) + min; | |
this.data[randomIndex].status = 'Working'; | |
this.data[randomIndex].updated = new Date(); | |
}, 2000); | |
} | |
detached() { | |
cancelInterval(this.interval); | |
} | |
} | |
class Row { | |
constructor(id, title, created, updated, status) { | |
this.id = id; | |
this.title = title || 'No title'; | |
this.created = new Date(); | |
this.updated = new Date(); | |
this.status = status || 'N/A'; | |
} | |
} |
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> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment