我如何在FancyBox中加载BB视图?

时间:2012-10-09 23:39:46

标签: jquery ruby-on-rails backbone.js fancybox

这似乎是一个微不足道的问题,我可能会对语法感到困惑。

基本上,我希望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. 如何渲染该视图。
  3. 谢谢!

1 个答案:

答案 0 :(得分: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/

相关问题