Backbone.js turning off wrap by div in render

前端 未结 3 944
感动是毒
感动是毒 2020-12-13 19:50

I have model Post and collection Posts. And want to make form with list of all post in

提交评论

  • 2020-12-13 20:21

    In version 0.9.0, Backbone introduced view.setElement(element) to handle this operation.

    0 讨论(0)
  • 2020-12-13 20:25

    If you don't define an el (or tagName) for the view (in the class or during instantiation) the view will be placed inside a div tag. http://documentcloud.github.com/backbone/#View-el

    var PostView = Backbone.View.extend({
      tagName: 'option'
    });
    

    UPDATE

    Starting v0.9.0, Backbone has view.setElement(element) to get this done.

    var PostView = Backbone.View.extend({
        initialize: function() {
            var template = _.template('<option value=""><%= title %></option>');
            var html = template({title: 'post'});
            this.setElement(html);
        }
    });
    
    0 讨论(0)
  • 提交回复
    热议问题