notification_dropdown_view.js:
initialize: function(){
$(document.body).click($.proxy(this.hideDropdown, this));
this.notifications = [];
this.perPage = 5;
this.hasMoreNotifs = true;
this.badge = this.$el;
this.dropdown = $("#notification-dropdown");
this.dropdownNotifications = this.dropdown.find(".notifications");
this.ajaxLoader = this.dropdown.find(".ajax_loader");
this.perfectScrollbarInitialized = false;
},
hideDropdown: function(evt){
var inDropdown = $(evt.target).parents().is($(".dropdown-menu", this.dropdown));
var inHovercard = $.contains(app.hovercard.el, evt.target);
if(!inDropdown && !inHovercard && this.dropdownShowing()){
this.dropdown.removeClass("dropdown-open");
this.destroyScrollbar();
}
}
header_view.js:
app.views.Header = app.views.Base.extend({
templateName: "header",
className: "dark-header",
events: {
"focusin #q": "toggleSearchActive",
"focusout #q": "toggleSearchActive"
},
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
podname: gon.appConfig.settings.podname
});
},
postRenderTemplate: function(){
new app.views.Notifications({ el: "#notification-dropdown" });
this.notificationDropdown = new app.views.NotificationDropdown({ el: "#notification-dropdown" });
new app.views.Search({ el: "#header-search-form" });
},
menuElement: function(){ return this.$("ul.dropdown"); },
toggleSearchActive: function(evt){
// jQuery produces two events for focus/blur (for bubbling)
// don't rely on which event arrives first, by allowing for both variants
var isActive = (_.indexOf(["focus","focusin"], evt.type) !== -1);
$(evt.target).toggleClass("active", isActive);
return false;
}
});
在RoR应用中,当同时点击某个图标时,会打开一个下拉菜单并关闭通知。 hideDropdown应该在打开时隐藏下拉列表,但它没有,我收到错误:
未捕获的TypeError:无法读取未定义的属性“el”
我认为它与“this”有关。有人可以帮忙吗?
答案 0 :(得分:0)
您是否已将el分配给视图?像:
headerView = new App.Views.HeaderView
el: '#header'
您可以为视图指定el的选择器 http://backbonejs.org/#View-el