Code Monkey home page Code Monkey logo

Comments (2)

primetwig avatar primetwig commented on May 29, 2024

Hello.

I wish I knew the way you follow to sort items.
Some people respect order of items in array,
but others use prop position in every item.

Nestable has a method getPathById(id, items).
You can try to use it directly (so far I have no intention to change it),
or better copy it to your utils (just for being on a safe side).

Your code would look something like:

state = {
  items: [] // let's say your items are in state
};
handleChange = (items, item) => {
  const from = refToNestable.getPathById(item.id, this.state.items);
  const to = refToNestable.getPathById(item.id, items);
};

Please notice another method as well: getItemByPath(path, items).

from react-nestable.

rickvandermey avatar rickvandermey commented on May 29, 2024

I rewrote the layout for my json to your example to minimize bugs.
I've played a little with those functions but ended up in writing a function

maybe it is helpfull for this project to implement to get the parent

id = item.id
array = items

processArray(id, array, parentId){
  array.map((i) => {
   const itemId = i.id;
   if(itemId != null && itemId === id) {
     if(parentId){
      this.props.actions.patchSortedPage(id, parentId);
    }
  }
  if(typeof(i.children) === 'object' && i.children.length > 0) {
    return this.processArray(id, i.children, itemId );
  }
});}

from react-nestable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.