문제

I know how to construct a jQuery object from an Ember view which is in the DOM:

App.myView = Ember.View.extend({
  elementId: "my_view",

  didInsertElement: function(){
    console.log(this.$().attr('id'))  // outputs 'my_view'
  }
});


<!-- HTML output -->

<div id="my_view">
   <!--  ...   -->
</div>

How about doing the inverse. Given a jQuery object, how do I get the corresponding Ember View object.

function(selector){
   $el = $(selector);
   // ???
}
도움이 되었습니까?

해결책

function getClosestEmberView($el) {
  var id = $el.closest('.ember-view').attr('id');
  if (!id) return;
  if (Ember.View.views.hasOwnProperty(id)) {
    return Ember.View.views[id];
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top