2015-07-21 67 views
0

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; 
    } 
}); 

在回報率的應用程序,同時在圖標上點擊時,下拉打開和關閉的通知。 hideDropdown應該隱藏下拉打開時,但它沒有做,我得到的錯誤:

遺漏的類型錯誤:無法讀取的不確定

財產「厄爾尼諾」我相信它是與「本」 。誰能幫忙?

+0

你可以在Chrome瀏覽器中的錯誤的堆棧跟蹤,然後讓我們知道哪一行到底是引發錯誤。更好的是,在該行上放置一個斷點並遍歷堆棧以查看元素未定義的原因。 –

+0

這將是我第一次進行調試。在閱讀你寫的和一些研究成果後,我已經掌握了基礎知識。我不知道它是如何在rails應用程序中完成的,有些人使用調試器gem for rails。我想知道哪裏適合骨幹用途? – Mohammed

+0

https://developer.chrome.com/devtools/docs/javascript-debugging&https://developer.chrome.com/extensions/tut_debugging - 這些應該會幫助你開始。 –

回答

0

您是否已將el分配給視圖?像:

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

你可以指定EL選擇到您的視圖 http://backbonejs.org/#View-el

+0

不,這個類被稱爲notification_dropdown_view.js,並且與下拉列表中的通知呈現有關。還有另一個叫header_view.js的類更新,所以你可以看到。 – Mohammed