Answer the question
In order to leave comments, you need to log in
How to make a nested list from MongoDB?
Good afternoon,
I am developing an application for NodeJS, and now it became necessary to create a nested list, and the elements of which can be dragged. The script is already there - [URL=" ilikenwf.github.io/example.html "]nestedSortable[/URL], it contains certain classes to get the current sort. So you can, for example, get in JSON: [{'id': 1, 'children': [{'id': 2},{'id': 3}] } ]
And then, restore according to this sorting, this was implemented, but a problem arose: if a person searches for records, then a simple list will be displayed to him, because these records are in different categories, each of which has its own sorting))
And so, I came to the conclusion that I need to make a special field for each record containing the parent_id, so I can restore sorting anywhere. And so the question. How can I update the database when dragging (update the parent_id of each changed field). Here is an example:
Answer the question
In order to leave comments, you need to log in
There is a change method. Or relocate. It is necessary on it, to transfer the value by Ajax to the server and save it there.
There are 2 methods for storing tree hierarchies. One is what you wrote where there is a parent_id and the other is called nested sets. Google it. For me, it is much better, although it takes more time to figure it out. In nested set you will have 2 fields left and right.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question