Jquery 在html中更改后如何再次初始化视图

Jquery 在html中更改后如何再次初始化视图,jquery,fancybox,backbone.js,Jquery,Fancybox,Backbone.js,我在backbone.js中有一个视图 App.Backbone.UserView = Backbone.View.extend({ tagName: 'li', className: 'pp-entry group', template :_.template('<img src="i/pp-pic-8.png" class="pp-pic" alt="" /><a class="pp-pic-wrap show-fb" hre

我在backbone.js中有一个视图

App.Backbone.UserView = Backbone.View.extend({
        tagName: 'li',
        className: 'pp-entry group',
        template :_.template('<img src="i/pp-pic-8.png" class="pp-pic" alt="" /><a class="pp-pic-wrap show-fb" href="#pp-details-<%=username%>"></a>),
        templatedetails:_.template('`<div style="display:none"><div id="pp-details-<%=username%>" class="pp-details"><div class="cta clear"><input type="button" name="" value="Add to my Wallet" class="mar-right-10 addtowallet" /><input type="button" class="mar-right-10 addtogib" name="" value="Add to gib as link" /><input type="button" name="" value="Close" onclick="$.fancybox.close()" /></div></div><.div>'`)

        //Here is the click event defined

        events:{    
            "click .addtowallet":"addlinktowallet",
            "click .addtogib":"addasgiblink"
            },

       //Render contents

       render: function() { 
        $(this.el).html(this.template(this.model.toJSON()));
        $(this.el).attr('id', 'pp-'+this.model.get('username')); //This is used to set the id for the "li" tag

        $(this.el).append(this.templatedetails(this.model.toJSON())); //appending to the template
     $(".show-fb").fancybox();
        },

        //But when i am defining the function the click event does not get triggered

        addasgiblink: function(){
            alert("gib button clicked");        
            },

        addlinktowallet: function(){
            alert("wallet button clicked");     
            }
});
App.Backbone.UserView=Backbone.View.extend({
标记名:“li”,
类名:“pp条目组”,
模板:u.template('),
templatedetails:u.template('```)
//下面是定义的单击事件
事件:{
“click.addtowallet”:“addlinktowallet”,
单击.addtogib:“addasgiblink”
},
//呈现内容
render:function(){
$(this.el).html(this.template(this.model.toJSON());
$(this.el).attr('id','pp-'+this.model.get('username');//用于设置“li”标记的id
$(this.el).append(this.templatedetails(this.model.toJSON());//追加到模板
$(“.show fb”).fancybox();
},
//但在定义函数时,不会触发单击事件
addasgiblink:function(){
警报(“点击gib按钮”);
},
addlinktowallet:函数(){
警报(“点击钱包按钮”);
}
});
这是生成html的过程。 当我分析时,这里发生的事情是fancy box正在我的div中添加他的html,所以addlinktowallet上的clickevnet和其他工具都不起作用。 请建议我如何使用fancybox

<li id="pp-rahul" class="pp-entry group">
<img class="pp-pic" alt="" src="i/pp-pic-8.png">
<a class="pp-pic-wrap show-fb" href="#pp-details-rahul"></a>

<div style="display: none;">
 // added by fancybox 
<div style="width: auto; height: auto; overflow: auto; position: relative;">
<div id="pp-details-rahul" class="pp-details">
<img class="pp-pic" alt="" src="i/pp-pic-2.png">
<h4 class="pp-name">rahul</h4>
<p class="pp-attr">
</p>
<p class="pp-attr mar-btm-20">
       //here other html are coming .
</p>
<div class="cta clear">
   //here the html of button 
</div>
</div>
</div>
</div>
</li>
  • //由fancybox添加 拉胡尔

    //下面是其他html。

    //这里是按钮的html
  • 在视图代码中使用
    live()
    注册单击事件-


    文档-

    更改html后如何再次初始化视图:再次调用渲染函数

    定义的主干事件在呈现视图时被注册为事件委托,从而消除了必须在特定元素上调用JQuery的Live事件的要求

    主干文档非常广泛:

    delegateEvents:使用jQuery的委托函数为视图中的DOM事件提供声明性回调

    与在渲染期间手动使用jQuery将事件绑定到子元素相比,使用delegateEvents提供了许多优势。所有附加的回调在传递给jQuery之前都会绑定到视图,因此当调用回调时,它会继续引用视图对象。当delegateEvents再次运行时,可能会使用不同的事件哈希,所有回调都会被删除并重新委派-这对于在不同模式下需要不同行为的视图非常有用


    好的,谢谢你已经使用了直播活动,无论如何谢谢你的回答。我正在使用fancybox,我可以不用
    直播
    ,如果可以,请用代码更新你的回答。