Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript backbone.js中的多次单击事件_Javascript_Jquery_Backbone.js_Views - Fatal编程技术网

Javascript backbone.js中的多次单击事件

Javascript backbone.js中的多次单击事件,javascript,jquery,backbone.js,views,Javascript,Jquery,Backbone.js,Views,在我更改代码中的options.channel_id之后,单击处理程序将被触发两次。我想在我的类中有两个视图要打包id。如何删除相关元素中以前的视图 我尝试了empty()和停止侦听没有任何效果。我认为您需要。删除() 从DOM中删除视图及其el,并调用stopListening以删除该视图已侦听的所有绑定事件 我想您需要。删除() 从DOM中删除视图及其el,并调用stopListening以删除该视图已侦听的所有绑定事件 var $ = jQuery = require('jquery')

在我更改代码中的options.channel_id之后,单击处理程序将被触发两次。我想在我的类中有两个视图要打包
id
。如何删除相关元素中以前的视图

我尝试了
empty()
停止侦听
没有任何效果。

我认为您需要。删除() 从DOM中删除视图及其el,并调用stopListening以删除该视图已侦听的所有绑定事件

我想您需要。删除() 从DOM中删除视图及其el,并调用stopListening以删除该视图已侦听的所有绑定事件

var $ = jQuery = require('jquery'),
    Backbone = require('backbone'),
    Handlebars = require('handlebars'),
    _ = require('underscore'),
    Filter = require('../../libs/filters'),
    orderActionTemplate = require("../../templates/order/OrderAction.html"),
    orderListView = require('./OrderListView');

var OrderActionView = Backbone.View.extend({

    el: "#id-order-action",

    initialize: function (options) {
        var self = this;
        this.action = this.$el.find(".nav-pills li.active a").attr("action");
        if (options !== null && (typeof options !== 'undefined')) {

            self.channel_id = options.channel_id;
            self.channel_type = options.channel_type;
            this.getActions(self.channel_type, self.action); // By Default show to pack orders
            this.orderListView = new orderListView({
                action: self.action,
                channel_id: self.channel_id,
                el: ".id-to-pack"
            });
        } else {
            this.orderListView = new orderListView({
                action: self.action,
                el: ".id-to-pack"
            });

        }
        return this.orderListView;
    },

    events: {
        "click a.a-action": "getActiveTabActions"
    },

    getActiveTabActions: function (e) {
        var self = this;
        e.preventDefault();
        var liTab = $(e.currentTarget).attr("action");
        this.getActions(this.channel_type, liTab);
        console.log(self.channel_id);

        if (typeof self.channel_id !== 'undefined') {
            this.orderListView = new orderListView({
                action: liTab,
                channel_id: self.channel_id,
                channel_type: self.channel_type,
                el: ".id-to-pack"
            });
        }

    },

    getActions: function (channel_type, tab) {
        if (typeof channel_type === 'undefined') channel_type = "DEFAULT";

        if ((typeof tab !== 'undefined')) {
            var actions = Filter.actions[channel_type][tab]();
            this.$el.find("#" + tab + "-action").html(actions);
        }

    },

    render: function () {
        // this.$('.id-to-pack').empty().off();
        this.$el.html(orderActionTemplate);
        // this.orderListView.setElement(this.$('.id-to-pack')).delegateEvents().render();

    }
});