Backbone.js - How are models / views related to the DOM element?

I just play with backbone.js and jQuery magic to prepare for some upcoming projects.

One test case contains a table whose rows are displayed using the main mode. They are well reviewed when the value changes. After that, the entire table is sorted using the jQuery plugin (Animated Table Sort), the rows are moved to new positions. In fact, this process works once, but the next time the lines appear twice, everything ends in chaos.

Is it possible that the relationship between the DOM element and the underlying view cannot handle such a change? Are there any workarounds?

+4
source share
3 answers

When you develop with the Model / View infrastructure, such as backbone.js or knockout.js, I believe that you need to rebuild your thoughts and implementations in order to change what diplayed (like sorting) is in Model, and not Allow them to appear in the view (for example, using the jquery plugin).

If you end up using the script view in the view to do something fantastic (animation is a good example), then you decide whether the model is updated correctly by disabling or expanding the binding.

Also note that, according to the documentation, this animated sorting plugin removes your table rows from the DOM, adds them to new DIVs, animates them, removes them from the DIV, and restores them to the table. I am wondering if, after this, everything will end, the spine has lost traces of these TDs, and when it changes after the change, it simply adds a new set, since the last set is โ€œgoneโ€.

+3
source

Thank you for your responses. Indeed, the table sorter does a lot that makes it difficult for fpr to maintain bindings. I switched to the excellent Quicksand plugin , which uses a hidden list to animate changes to another (visible) list. Fits better for backbone.js.

+1
source

Your collection maintains order for your models, and therefore your respective views. If an external force (for example, the jQuery table sorting plugin) changes the order of views, this change is not reflected in essence in the Backbone collection, so everything is not synchronized quickly.

In addition, if a table sorter clones elements and deletes the original, Backbone will most likely lose track of the views and eventually recreate them.

0
source

Source: https://habr.com/ru/post/1344011/


All Articles