Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created October 21, 2013 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradoyler/7078567 to your computer and use it in GitHub Desktop.
Save bradoyler/7078567 to your computer and use it in GitHub Desktop.
An Ember.js controller that fetches data and binds to a template without using a router. Helpful if you have mutiple requests with a single Route. Uses the PromiseProxyMixin on a ObjectProxy
<ul class="article-list">
{{#each view.content.articlelist}}
<li>
{{#link-to 'article' this }} {{headline}} {{/link-to}}
</li>
{{/each}}
</ul>
define([
'ember',
'../../models/article'
], function(Ember, Model) {
var exports;
var PromiseWrapper = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);
exports = Ember.ObjectController.extend({
model: function(){
return PromiseWrapper.create({
promise: Model.find({count:5}) // returns top 5 within a promise
});
}.property(),
articlelist: function() {
// do some manipulation of the articles and return them
return (this.get('model.results')||[]).slice(1);
}.property('model.isFulfilled')
});
return exports;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment