试图在主干网中隐藏下拉列表出错

trying to hide dropdown in backbone error

本文关键字:隐藏 下拉列表 出错 主干网      更新时间:2023-09-26

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应该在打开时隐藏下拉列表,但它没有,我得到了错误:

未捕获的类型错误:无法读取未定义的属性"el">

我想这与"这个"有关。有人能帮忙吗?

您是否已将el分配给视图?类似:

headerView = new App.Views.HeaderView
  el: '#header'

您可以在视图中指定el的选择器http://backbonejs.org/#View-el