jeudi 4 octobre 2018

Javascript updating tree object with new position of items

I am creating a drag and click feature - and have a parent/child object - which picks up a group and its re-arranged state. How do I update the stored object with a new re-arranged child - or parent re-arrangment.

So in this list

-- burger
++++++ pickle
++++++ lettus
++++++ tomato
-- kebab
++++++ ketchup
++++++ chilli
-- coffee maker
++++++ filter
++++++ grounds

and then I get an update the changes the order of the parent groups

-- coffee maker
++++++ filter
++++++ grounds
-- burger
++++++ pickle
++++++ lettus
++++++ tomato
-- kebab
++++++ ketchup
++++++ chilli

but then I may get an update the just changes a child branch e.g burger branch

-- coffee maker
++++++ filter
++++++ grounds
-- burger
++++++ tomato
++++++ lettus
++++++ pickle
-- kebab
++++++ ketchup
++++++ chilli

latest js fiddle. http://jsfiddle.net/0ht35rpb/448/

would need to loop through the stored object --- detect if the new arrangement of items is a parent or child branch --- update the stored object accordingly. Jsfiddle didn't recognise .find as a function though

options.forEach(group => {
    console.log(group)
  //const foundMember = group.find(member => member.id === firstItem.id);
  //console.log("foundMember", foundMember);
  //if (foundMember) {

  //}

});




Aucun commentaire:

Enregistrer un commentaire