Hey all,
Haven’t touched Ember in a bit and now getting back into it.
Trying to wrap my head around reopenClass(). I created the following class in my demo app which will be my model:
App.RedditLink = Ember.Object.extend({
thumbnailUrl: function() {
var thumbnail = this.get('thumbnail');
return (thumbnail === 'default') ? null : thumbnail;
}.property('thumbnail')
});
Then I’m using reopenClass() to pull data from Reddit and render it:
App.RedditLink.reopenClass({
findAll: function(subreddit) {
var links = [];
$.getJSON("http://www.reddit.com/r/" + subreddit + "/.json?jsonp=?").then(function(response) {
response.data.children.forEach(function (child) {
links.pushObject(App.RedditLink.create(child.data));
});
});
return links;
}
});
The question I have is “why do I need to use reopenClass() for this? Why can’t I just specify my findAll() method in my original class declaration?”
When I’ve tried to move findAll() into the App.RedditLink = Ember.Object.extend({…}) declaration, I get all types of errors.
The full mini-app code is here: Free large file hosting. Send big files the easy way! Demo link is here: http://reybango.com/demos/ember/reddit/index.html
Help?