Created
October 21, 2013 04:12
-
-
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
This file contains 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
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