Latest Ember + Data
by MikeAski
HTML
<script src="https://github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
<script src="https://github.com/downloads/emberjs/data/ember-data-latest.js"></script>
<script src="http://benalman.com/code/javascript/ba-linkify.js"></script>
<script type="text/x-handlebars" data-template-name="item">
{{linkify view.content.urlText}}
<br/>
{{formatDate view.content.createdAt}}
</script>
<script type="text/x-handlebars" data-template-name="items">
{{view Ember.CollectionView contentBinding="controller" itemViewClass="App.ItemView"}}
or
{{#each item in controller}}
{{view App.ItemView contentBinding="item"}}
{{/each}}
</script>
JavaScript
Ember.Handlebars.registerHelper('linkify', function(path, options) {
var rawText = Ember.getPath(options.data, path);
var url = linkify(rawText);
return Ember.String.htmlSafe(url);
});
Ember.Handlebars.registerHelper('formatDate', function(path, options) {
var rawDate = Ember.getPath(options.data, path);
return new Date(rawDate).toLocaleString(); // or whatever format you need...
});
App = Ember.Application.create();
App.ItemsController = Ember.ArrayController.extend();
App.ItemsView = Ember.View.extend({
templateName: 'items'
});
App.ItemView = Ember.View.extend({
templateName: 'item'
});
App.ItemsView.create({
controller: App.ItemsController.create({
content: [{
urlText: 'http://my/stuff/url',
createdAt: '2012-06-09 11:56:29'
}, {
urlText: 'http://my/other/stuff/url',
createdAt: '2012-06-09 12:37:52'
}, {
urlText: 'http://my/last/stuff/url',
createdAt: '2012-06-09 15:26:45'
}]
})
}).append();