Tại sao tôi phải tạo toàn bộ close prototype chỉ để các sự kiện của tôi bị hủy liên kết khỏi chế độ xem của tôi? Không nên xương sống chỉ cần xây dựng mà? Có cách nào để phát hiện khi một chế độ xem đang bị xóa không?Sự kiện trục chính kích hoạt hai lần
Sự kiện xương sống của tôi kích hoạt hai lần sau khi tôi điều hướng và quay lại chế độ xem.
events : {
"click #userDropdownButton > a" : "toggleUserDropdownMenu",
"click" : "hideUserDropdownMenuIfClickedOutside"
},
el : "body",
initialize : function() {
this.render();
},
// Shows/hides the user dropdown menu
toggleUserDropdownMenu : function() {
if(!this.$el.find('#userDropdownButton > ul').is(':visible')) {
this.showUserDropdownMenu();
} else {
this.hideUserDropdownMenu();
}
return false;
},
showUserDropdownMenu : function() {
this.$el.find('#userDropdownButton').addClass('hover');
this.$el.find('#userDropdownButton > ul').show();
this.$el.find('#userDropdownButton > a .arrow-down').removeClass('arrow-down').addClass('arrow-up');
},
hideUserDropdownMenuIfClickedOutside : function() {
if(this.$el.find('#userDropdownButton > ul').is(':visible')) {
this.hideUserDropdownMenu();
}
},
hideUserDropdownMenu : function() {
this.$el.find('#userDropdownButton').removeClass('hover');
this.$el.find('#userDropdownButton > ul').hide();
this.$el.find('#userDropdownButton > a .arrow-up').removeClass('arrow-up').addClass('arrow-down');
},
Lần đầu tiên xem là ra, thả xuống sẽ mở ra và đóng lại đúng cách, nhưng trên lần thứ hai xem là ra, thả xuống giải thích mỗi nhấp chuột hai lần, vì vậy ngay sau khi nó mở ra, đóng cửa nhấp chuột thứ hai nó.
Nếu chúng tôi biết bạn đang làm gì thì chúng tôi có thể cho bạn biết bạn đang làm gì sai. Có lẽ nếu có một số mã để xem xét ... –
@muistooshort thêm mã :) cảm ơn cho các thông tin phản hồi – Garrett
Tôi muốn gọi đây là một bản sao của http://stackoverflow.com/q/10966440/479863 hoặc ít nhất là câu trả lời là khá nhiều như nhau. –