-1

Im my popover module the template is loaded view ajax.

function(app) {

  var Popover = app.module();

  Popover.Views.Default = Backbone.View.extend({
    template: "popover/template",

    initialize: function(options) {
      this.reference = options.reference;
      this.render();
    },

    beforeRender: function() {
      this.content = this.$el.find('.popover');
    }
  });

  // Required, return the module for AMD compliance.
  return Popover;
});

Renders:

<div>
    <div class="popover">content</div>
</div>

While the template just includes

<div class="popover">content</div>

How can I remove the sorrounding div?

4

1 回答 1

1

尝试将render函数重写为:

 render:function () {
     this.$el.html(_.template(this.template));
     return this;
 }

如果您正在使用underscore加载模板...


如果你只想要div你可以添加className到视图中:

Popover.Views.Default = Backbone.View.extend({
    template: "popover/template",

    className: 'popover',

    initialize: function(options) {
      this.reference = options.reference;
      this.render();
    },

    beforeRender: function() {
      this.content = this.$el.find('.popover');
    }
  });

那么模板只有内容,没有div.

于 2013-06-28T12:13:28.300 回答