Skip to content

Instantly share code, notes, and snippets.

@jlsuttles
Last active December 20, 2015 05:19
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 jlsuttles/6077500 to your computer and use it in GitHub Desktop.
Save jlsuttles/6077500 to your computer and use it in GitHub Desktop.
I want to initialize a jQuery plugin when the content for an Ember.View has loaded.

This is the code I think I want, but it is never executed.

App.ThumbnailScrollerView = Ember.View.extend({
  tagName: "div",
  didInsertElement: function() {
    return this.get("controller.content").addObserver("isLoaded", function() {
      return $(".jThumbnailScroller").thumbnailScroller;
    });
  }
});

This code is executed, but once for each object, I really only want it for the last object.

App.ThumbnailScrollerView = Ember.View.extend({
  tagName: "div",
  didInsertElement: function() {
    return this.get("controller.content.@each").addObserver("isLoaded", function() {
      return $(".jThumbnailScroller").thumbnailScroller;
    });
  }
});

This is also never executed.

App.ThumbnailScrollerView = Ember.View.extend({
  tagName: "div",
  didInsertElement: function() {
    return this.get("controller.content.lastObject").addObserver("isLoaded", function() {
      return $(".jThumbnailScroller").thumbnailScroller;
    });
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment