Backbone Marionette 如何访问包含视图的元素?

Bacbone Marionette how to get access to an element in which the view is wrapped up?

我有 CollectionView,它有 tagName 和 Id/tagClass。我注意将插件应用于 onRender 事件上的 'tagName' 元素。我无法通过 this.el.

访问它
var ListView = Backbone.Marionette.CollectionView.extend({
    tagName:'article',
    className:'myClass',
    id:'myID',
    childView: ListItemView,
    onRender: function () {

        (access to view tagName el).readmore({
            speed: 500
        });
    }
});

大多数第三方插件(尤其是 jQuery 插件)的工作方式是,它们操作的元素必须附加到 DOM。

所以你必须这样做:

var listView = new ListView();
$someElement.append(listView.render().el); // Your view is in the DOM now
listView.attachPlugins();                  // And you can attach plugins

其中 attachPlugins 类似于:

attachPlugins: function () {
  this.$el.readmore({
            speed: 500
        });
}