2

我有一个视图,它在某些选择控件上定义了一个更改事件,但它们似乎没有被触发。视图是这样的:

var FiltersView = Backbone.Marionette.ItemView.extend({
    template: FiltersTmpl,
    events: {
        'change #panel_filters select': 'enableSearch'
    },
    enableSearch: function() {
        debugger;
    }
});

当我更改下拉菜单时,enableSearch不会触发。但是,使用 Chrome 开发工具,我可以使用 jQuery 来设置这样的事件处理程序$("#panel_filters select").change(function() { debugger; });,并且确实会触发。所以我知道选择器是正确的,并且选择正在触发更改事件。我知道这一定是一个简单的语法问题,但对我来说似乎是正确的语法。

4

1 回答 1

2

Ok I figured it out. #panel_filters is actually the element that I injected my view into. Technically, it's considered outside the view. And apparently, view events are scoped to the view itself. Which is handy I suppose, but I didn't know that. Good to know :-)

于 2013-09-06T15:41:53.547 回答