2013-08-27 99 views
0

我正在使用twitter引导程序链接。当用户点击链接时,会出现一个引导模式。 现在由于模态渲染的一些bootstrap技术困难,我需要分离链接并将模式从navbar div中移出。如何将骨干网集合呈现为两个视图

所以考虑我有两个单独的div

     <div id="linkDiv"> 

         </div> 

     <div id="modalDiv"> 

         </div> 

现在我只有一个视图,这使得服务器的调用获取集合

app.View.FriendRequestListView = Backbone.View.extend({ 
templateModalLink: _.template($('#link').html()), 
templateModal: _.template($('#modal').html()), 

tagName: 'div', 

initialize: function(){ 
    this.friendRequestCollection = new app.Collection.FriendRequestCollection(); 
    this.friendRequestCollection.bind("reset", this.render, this); 
    this.friendRequestCollection.fetch(); 
}, 

render: function() { 
    $(this.el).html(this.templateModalLink({ 
     friendRequestCollection: this.friendRequestCollection})); 
    return $(this.el); 
}, 
}); 

比我可以只渲染一个格如下

var list = new app.View.FriendRequestListView(); 
    $('#linkDiv').html(list.$el); 

我的问题是,是否有可能在同一时间呈现两个模板和两个模板添加到不同的DIV例如像在我的情况我想更新 templateModalLink模板linkDiv和templateModal模板modalDiv与我从服务器获取的集合。

+0

能否请您阐述更 –

回答

0

你必须实例app.View.FriendRequestListView(S)之前的收集和传递app.View.FriendRequestListView(S)集合:

var friendRequests = new app.Collection.FriendRequestCollection(); 
friendRequests.fetch(
    success: function(collection, response, options) { 
     var list1 = new app.View.FriendRequestListView({collection: collection}); 
     var list2 = new app.View.FriendRequestListView({collection: collection}); 

     $('#linkDiv').html(list1.$el); 
     $('#modalDiv').html(list2.$el); 
    } 
); 
+0

,我应该在改变什么我的FriendRequestListView。它看起来如何.. –

+0

哦,我解决了它...非常感谢... –