E
E
eldarkaa2015-11-09 10:46:47
JavaScript
eldarkaa, 2015-11-09 10:46:47

How to work with a model that has nested models?

The project is simple: From the MK (MicroController) data comes to the web server. Then the user can access the web server and get the data and manipulate it.
I know very little about Backbone.JS and JavaScript, but I have already watched quite a few video guides that did not help me solve the problem. From what I understand, Backbone avoids nested models.
I first tried to implement option 1 (Fig. 1). JSON went down from the very top. WaterSystem>Plants>Plant
It turned out not bad, but when interacting with each view, incorrect data is displayed, in this case id (Fig. 3.4). And further, in the video, each time the emphasis was on the fact that the collections were fetched separately.
Everything goes to the fact that it is necessary to separate the WaterSystem and the Plants collection into separate entities, that is, request JSON for them separately. For almost every Plant, request JSON. This is shown in option 2 (Figure 2).
----------------------------
What I want to get: 1 JSON updates all models. When the user changes the view, the model is normally edited and sent to the server.
Question. Help me choose the right structure for nested models! And what am I doing wrong?
Code here: https://bitbucket.org/darkDesire/watersystemfront
Figure 1
3b8e02c207444f5dbdc9af6efe8d298a.png
Figure 2
86d7752fbb9d42bb852c9dc6bb58179e.png
Figure 3
97e3c300a7f647ae8331733632f44bd0.png
Figure 4
9f7abd293e944dff81bca0e6bd57e63f.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-11-09
@eldarkaa

Out of the box, Backbone, alas, does not work with nested models. If you have really nested models, then look at Backbone-relational or Backbone.NestedTypes . If you can get by with nested properties, then Backbone-nested .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question