【发布时间】:2014-05-16 13:37:50
【问题描述】:
我有一个 Backbone 集合和 Marionette CollectionView 呈现在一个无序列表中。我只是想让它可排序,所以我需要等到collectionView被放置在DOM中。
我可以监听在集合被渲染时触发的事件,但是当集合被放置在 DOM 中时我不知道如何做同样的事情。
var ContactView = Backbone.Marionette.CollectionView.extend({
id : "contacts",
tagName: "ul",
itemView: UserView,
initialize: function(){
this.triggerMethod("collection:rendered", this);
}
});
var collection = new ContactView({ collection: myContacts });
listenTo(collection, "collection:rendered",usersRendered);
$("#content").append(collection.render().el);
usersRendered: function(){
$("#contacts").sortable(); // #contacts not in the DOM yet
}
【问题讨论】:
-
您的问题是如何判断 CollectionView 何时已附加到 DOM?
标签: jquery-ui backbone.js marionette