Backbone.js views and models correlation?

Oskar

Background: I'm using Backbone for the first time. In my project, I have one "main" model - let's call it Customer. At all times, only one Customer is displayed. I have a CustomerList Collection, which queues the Customers. At a button click, the next Customer is displayed. CustomerView does all the rendering etc.

The problem: should I make a new instance of CustomerView every time we switch to the next Customer? Another possibility (which I started out with) was just one instance of the View and passing the model to the render function of the view (view.render(model)). This way, I can get the next Customer from the List, pass it on to the render function of the view and that's it. I'm wondering though how well this suits the MVC pattern of Backbone? It would seem more "standard" to get the new model, kill the current View and make a new View instance.

Any suggestions from experienced Backbone developers, please? Thanks.

Lix

If the only thing that is changing is the actual model then you should definitely keep your CustomerView around and simply provide it a new model to display.

This most certainly pertains to MVC concepts of functional separation. The CustomerView only needs the relevant data (supplied by the model) in order to perform it's task of rendering the view.

Think of it like this - is there any need to reset your CustomerView module? It shouldn't hold and model specific information at all so essentially it shouldn't care that you change the model - only that it needs to be re-rendered once the data changes.


The one instance where it would make sense to me to totally "kill" the current view would be if the user navigates to a different section of your application that has no relation to customers and has no option to view customer details. Only then would it make sense to completely release un-needed modules.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Backbone JS - Combination of collection, views and models

From Dev

Is it an anti-pattern to instantiate models in views in Backbone.js?

From Dev

Using Backbone.js depended views, models, views' render funcs, listening to events, from another View

From Dev

Using backbone with multiple views and little models

From Dev

How to fold backbone models, views and collections in vim?

From Dev

Code not working when using models and views - Backbone

From Dev

Backbone JS, navigating different views

From Dev

inception models backbone.js

From Dev

Backbone JS Models: Hiding a dropdown

From Dev

Creation of backbone views/models based up on server side Objects' structure

From Dev

how to switch views with the backbone.js router?

From Dev

Backbone.js is not rendering views properly

From Dev

Views and appending table rows in backbone.js

From Dev

Backbone.js is not rendering views properly

From Dev

Backbone.js collection getting multiple models

From Dev

Backbone.js collection getting multiple models

From Dev

Warnings in passing three.js scenes into backbone.js models

From Dev

What exactly is this.el in Backbone.js views?

From Dev

Backbone.js parent vs. child views

From Dev

What is the order of events binded by Views in Backbone.js?

From Dev

Re-rendering backbone.js views on resize?

From Dev

How to load multiple Backbone.js views on a single page

From Dev

Passing Data to Views in Backbone Js does not see in the browser

From Dev

backbone js view event binding only to views elements

From Dev

Adding views to different el based on condition in Backbone.js

From Dev

Best way to start a backbone.js app with multiple views and routes

From Dev

What exactly is this.el in Backbone.js views?

From Dev

Using backbone-validation.js on a model without views

From Dev

Backbone.js views will not display on page load, but works with jQuery in console

Related Related

  1. 1

    Backbone JS - Combination of collection, views and models

  2. 2

    Is it an anti-pattern to instantiate models in views in Backbone.js?

  3. 3

    Using Backbone.js depended views, models, views' render funcs, listening to events, from another View

  4. 4

    Using backbone with multiple views and little models

  5. 5

    How to fold backbone models, views and collections in vim?

  6. 6

    Code not working when using models and views - Backbone

  7. 7

    Backbone JS, navigating different views

  8. 8

    inception models backbone.js

  9. 9

    Backbone JS Models: Hiding a dropdown

  10. 10

    Creation of backbone views/models based up on server side Objects' structure

  11. 11

    how to switch views with the backbone.js router?

  12. 12

    Backbone.js is not rendering views properly

  13. 13

    Views and appending table rows in backbone.js

  14. 14

    Backbone.js is not rendering views properly

  15. 15

    Backbone.js collection getting multiple models

  16. 16

    Backbone.js collection getting multiple models

  17. 17

    Warnings in passing three.js scenes into backbone.js models

  18. 18

    What exactly is this.el in Backbone.js views?

  19. 19

    Backbone.js parent vs. child views

  20. 20

    What is the order of events binded by Views in Backbone.js?

  21. 21

    Re-rendering backbone.js views on resize?

  22. 22

    How to load multiple Backbone.js views on a single page

  23. 23

    Passing Data to Views in Backbone Js does not see in the browser

  24. 24

    backbone js view event binding only to views elements

  25. 25

    Adding views to different el based on condition in Backbone.js

  26. 26

    Best way to start a backbone.js app with multiple views and routes

  27. 27

    What exactly is this.el in Backbone.js views?

  28. 28

    Using backbone-validation.js on a model without views

  29. 29

    Backbone.js views will not display on page load, but works with jQuery in console

HotTag

Archive