简体   繁体   中英

Binding Rivets.js before element in the DOM

I have a backbone view that has render() called from its parent view returning the sub-view which is then appended to the DOM. The problem is that I can't run

rivets.bind(this.$el, {user: this.user});

within the initialize method of the subview because the element is not in the DOM yet. I would rather not have to run another method after render to bind with rivets.

Probably a simple problem but any ideas?

I'm using a very similar pattern of views with subviews, and Rivets 0.3.8 has had no problem binding to jQuery objects that are only inserted into the DOM some time after being bound.

My render methods look something like this:

function render() {
    this.setElement(_.template('<html>...</html>', {tem: plate}));
    rivets.bind(this.$el, {riv: ets});
    return this;
}

Then later:

myView.render();
$('#myTarget').empty();
$('#myTarget').append(myView.el);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM