Answer the question
In order to leave comments, you need to log in
Is the code correct? Or can it be done more delicately?
Added a view for events related to one panel.
Am I doing everything right? It seems to work, but I feel that I am using the backbone tools for other purposes!
Is it correct to change DOM elements (in this case, changing the css class) directly, bypassing the model? And is it considered good practice to create a separate view for such things?
EA.Views.LeftPanel = Backbone.View.extend({
el: '#left-panel',
events: {
'click .email-folder': 'openFolder'
},
openFolder: function(elem) {
$('.email-folder').removeClass('active');
$(elem.target).addClass('active');
}
});
Answer the question
In order to leave comments, you need to log in
Do I understand correctly that .email-folder is the menu items?
This approach has the right to life, in my opinion.
Of course, in a good way, you need to create a model, set the is_active property in it and render the view in accordance with it, this is the whole point of MVVM frameworks.
But in such simple situations, I prefer not to complicate things.
Now, if you need, for example, to store the state of the panel in localStorage, or programmatically open folders, then you definitely need to use a collection of models.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question