4 ms·
If this solves your problem, then you probably didn't need MVC in the first place. But this doesn't necessarily decouple you from the DOM, and it sounds like a
by delambo 15y ago
If this solves your problem, then you probably didn't need MVC in the first place. But this doesn't necessarily decouple you from the DOM, and it sounds like all of the code that works with these models is a bunch of jQuery callbacks hooked into the DOM. Is that right?
If so, and your project is sizable, then an MVC, like backbone.js, could be beneficial.
- JesseAldridge 15y agoThe code can work with the models without touching the DOM. You just access the models via ids. eg parent_model = window.models[foo_model.get('parent_id')] parent_model.set('text', 'foo text') When you respond to a button click or whatever, then yeah, you use a jQuery callback. The model id is stored in the DOM element (the view) which you access with $(this). Whenever the model changes (via set), the render function is automatically called. The render function is responsible for passing attributes to a template which renders html. Then the render function sticks the html wherever it's supposed to go. I think that's basically how all MVC frameworks work under the hood.