Pergunta

Eu sei como construir um objeto jQuery a partir de uma visualização Ember que está no 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>

Que tal fazer o inverso.Dado um objeto jQuery, como obtenho o objeto Ember View correspondente.

function(selector){
   $el = $(selector);
   // ???
}
Foi útil?

Solução

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];
  }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top