简体   繁体   English

骨干视图中的drop事件

[英]drop event in backbone view

I'm trying to add a drop event in my backbone view but i can't get it right. 我试图在我的主干视图中添加一个drop事件,但是我做不到。 Below is the code I'm using and you can also check out this jsfiddle . 以下是我正在使用的代码,您也可以查看此jsfiddle

var View = Backbone.View.extend({

    events: {
        'drop .dropzone': 'drop'
    },

    drop: function(e) {
        e.preventDefault();
        alert('Dropping');
    },

    initialize: function() {},

    render: function() {}
});

$(function() {
    var view = new View({
        el: $('.dropzone');
    });
});​

if your view's el == .dropzone then you should do 如果您的视图的el == .dropzone,那么您应该

events: {
    'drop': 'drop'
},

if you specify just event type without selector it will listen to event on the view's root element - $('.dropzone') in this case. 如果仅指定事件类型而没有选择器,则它将在视图的根元素上监听事件-在这种情况下为$('。dropzone')。

The way you did it here would try to find .dropzone element among children of .dropzone element - and clearly it would fail to find this element at all 您在此处执行此操作的方式将尝试在.dropzone元素的子元素中查找.dropzone元素-显然,它将根本找不到该元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM