I’m looking into integrating Ember with an existing Rails application, to take advantage of Ember’s bindings, events (didInsertElement, etc.) …
Now I don’t want to transfer my erb views to handlebars, but instead I want to create Ember View objects and attach them to various elements already in the DOM. For example, I might have
<html>
<body>
<div class="header">
</div>
<div class="content">
</div>
<div class="footer">
</div>
</body>
</html>
and (on DOM ready) create a View for each element:
App.HeaderView = Ember.View.create({
// capture $('.header') to this
// console.log(this.$().attr('class')) should then output `header`
});
Ok the following works but I haven’t fully tested it.
Inspired by @pangratz’s pull request I extend
Ember.Viewwith the following method forBasically it copies the html content of the target element as well as its attributes. Then by just doing
the
.headerelement (that is already in the DOM) is now in App.HeaderView.See http://jsfiddle.net/KFcgA/4/