Calling a jQuery plugin in a Backbone render method

前端 未结 5 1741
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 16:09

I have a render method in Backbone that goes basically like this:

render: function () {
  $.tmpl(this.template, attrs).appendTo(this.el);
  return this;
},
         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 16:49

    Beter do it this way:

    action: function () {
        var container = $('#container');
    
        container.empty();
        myView.render(container);
    },
    
    render: function (container) {
        $(this.el)
            .append($.tmpl(this.template, attrs))
            .appendTo(container);
        $('label', this.el).inFieldLabels();
        return this;
    },
    

提交回复
热议问题