Last active
December 23, 2015 13:09
-
-
Save manoharank/6640182 to your computer and use it in GitHub Desktop.
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
// accessing controller in route's model hook | |
App.PostsRoute = Em.Route.extend({ | |
model: function() { | |
// getPosts will return a promise | |
return this.get('controller').getPosts(); | |
} | |
}); | |
App.PostsController = Ember.ArrayController.extend({ | |
getPosts: function() { | |
var self = this; | |
return ajax('/posts', { | |
'page': this.get('page'), | |
'sort_column': this.get('sort_column'), | |
'sort_order': this.get('sort_order') | |
}).then(function(json) { | |
self.set('content', json.posts); | |
}); | |
}, | |
getPostsAgain: function() { | |
Ember.run.once(this, 'getPosts'); | |
}.observes('page', 'sort_column', 'sort_order'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment