骨干视图多次触发事件

时间:2014-06-03 10:07:45

标签: javascript backbone.js backbone-views

以下是使用模型

填写数据的html代码
 <%_.each(leaves,function(leave){%>
    <div class="dash_div dash_grn no-padding-bottom" id="singleApproveDiv" >
        <div class="dash_title dash_gry">
            <h1 class="dash_inntitle al_emptxt">From: <%=leave.leave_date%> To:<%=leave.leave_date%></h1>   

            <%if(leave.leave_status=="1"){%>    
            <div id="<%=leave.leave_id%>">       
                <a class="singleCancel" id="can_<%=leave.leave_id%>" name="cancelSingleLeave" >Cancel</a>
                <a class="al_ynbtn apv_app" id="apr_<%=leave.leave_id%>" name="approveSingleLeave" ></a>
                <a class="al_ynbtn can_app" id="rej_<%=leave.leave_id%>" name="rejectSingleLeave"></a>
            </div>
            <%} %>

        </div>
    </div>
    <%})%>

查看js文件:

  render:function(){
$(this.el).html(this.template(this.model));
return this;    
  },

  events:{
'click a[id^="apr_"]': 'leaveAction',
'click a[id^="rej_"]': 'leaveAction',
'click a[id^="can_"]': 'leaveAction'
  },

  leaveAction: function(event) {
        console.log(event.currentTarget.name);
        //console.log(event.currentTarget.id);
        action = event.currentTarget.name;
        var leaves = self.model.leaves;
        var leaveStatus;
        switch (action) {

            case "approveSingleLeave":
                leaveStatus = "2";
                leaveId = event.currentTarget.id.substring(4);
                break;

            case "rejectSingleLeave":
                leaveStatus = "-1";
                leaveId = event.currentTarget.id.substring(4);
                break;

            case "cancelSingleLeave":
                leaveStatus = "0";
                leaveId = event.currentTarget.id.substring(4);
                break;
        }
  }

router.js

  leaveDetail: function(from, leaveRequestId) {
 require(['views/detailsView'], function(detailsView) {
     _this.views.detailsView = new detailsView({el: $("#wrapper"), model:  leaveDetailObj.toJSON()});
     _this.views.detailsView.render();

 });

 }

每当我在观看事件之间来回反复被解雇时,我已经多次反击&amp;第四种观点。

如何防止这种情况?

0 个答案:

没有答案