Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2013 16:10
Show Gist options
  • Save anonymous/6309322 to your computer and use it in GitHub Desktop.
Save anonymous/6309322 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars" id="application">
<h1>Data</h1>
<ul>
{{#each}}
<li>{{id}} - {{randomNumber}}</li>
{{/each}}
</ul>
</script>
</body>
</html>
App = Ember.Application.create();
function random(start, end) {
return Math.floor(Math.random * (end - start) + start);
}
App.StoreController = Ember.Controller.extend({
init: function() {
this._super();
var models = [];
this.set('models', []);
setInterval(function(){
var id = random(0, 5);
var randomNumber = random(0, 1000);
var model = models[id] || {id: id};
Ember.set(model, 'randomNumber', randomNumber);
//models.replace(id, 1,
models.pushObject(model);
}, 500);
}
});
App.Applicationroute = Ember.Route.extend({
model: function(){
this.controllerfor('store').get('models');
//this.get('store').push('person', {id: 1, name: "Yehuda"});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment