N
N
Nikita Nazarov2015-06-07 13:44:10
backbone.js
Nikita Nazarov, 2015-06-07 13:44:10

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

1 answer(s)
A
Alexey Ukolov, 2015-06-07
@Noz01

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.

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question