0

I have 3 different views, each of which share this same el value:

el:"<div id='main-inner'>"

and in the render function:

this.$el.html(html);

I was asked to combine all of these onto one page, so I'm trying to make a master view that has a collection of these views and renders each of the views within it. The problem is they each write to the same element, #main-inner and clear it's html before appending it's own html value. What is the proper way to change the el value before rendering from the master/wrapper view? Is this the best way to go about it?

Thanks!

4

2 回答 2

1

初始化视图时将 el 交给视图:

var view1 = new myView({el:'#div1'});
var view2 = new myView({el:'#div2'});
var view3 = new myView({el:'#div3'});

在您看来:

var myView = Backbone.View.extend({

   initialize: function(options){
     this.el = options.el; 
   }

});

现在你有了视图,每个渲染都在它自己的 el 中。

希望这能有所帮助。

于 2013-11-12T09:43:04.703 回答
-1

您可以将您的 el 定义为全局并使用它。例子:

App.Common.el = "";

利用 :

App.Common.el

于 2013-11-12T08:30:16.350 回答