2012-10-09 75 views
0

這似乎是一個微不足道的問題,我很可能會在語法上陷入困境。如何在FancyBox中加載BB視圖?

基本上,我想要一個FancyBox加載一個BB視圖,當我點擊一個鏈接時。

此前,它會加載一個BB的路線,並重定向到一個頁面所需的視圖和其他一切:

$('.edit_list').show().attr('href', '#lists/' + list.id + '/edit') 

我目前的看法

app.views.GlobalListEdit = Backbone.View.extend({ 
    tagName: "div", 
    className: "global_list_edit list_view", 
    title: 'Edit - ', 
    template: _.template('<div class="error"></div>' + 
    '<label for="global_list_edit_name">Group Name</label>' + 
    ... truncated ... 

我目前的jQuery

$('.edit_list') 
    .on('click', function(){ 
     // $.fancybox({ href: '#' + '#lists/' + list.id + '/edit' }); 
     //^bad idea #1 . This loads the whole other page sans the actual edit form.. 
     // $.fancybox({ new app.views.GlobalListEdit({el: $('body')}).render() }); 
     //^This psuedo code is more or less what I want. To load a new instant of the BB View. 
     return false; 
    }); 

所以我要找誰..

  1. 答案如何動態list.id傳遞給編輯打電話。
  2. 如何渲染該視圖。

謝謝!

回答

2

你可以用手$.fancybox一個jQuery對象和觀點有一個$el,所以你可以這樣做:

var v = new View({...}); 
$.fancybox(v.render().$el); 

演示:http://jsfiddle.net/ambiguous/ncmd7/

或者你可以用手$.fancybox的DOM元素:

var v = new View({...}); 
$.fancybox(v.render().el); 

演示:http://jsfiddle.net/ambiguous/t7Sbj/

+0

我很確定他們應該讓一個Mu是太短的雕像。 – Trip

+1

@Trip:謝謝,但「基座和任何狹小的密閉空間一樣是一座監獄。」歡迎您捐款給當地的動物收容所:) –

+1

會做!好想法。 – Trip