Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:05:19+00:00 2026-05-24T07:05:19+00:00

I have tree list but I need to get the parent and child value,

  • 0

I have tree list but I need to get the parent and child value, when sorting is completed.

jquery

var jsonObj = {
    "department":{
        "Title1":[
            {
                "child1":"Green",
                "child2":"Yellow"
            },
            {
                "child3":"Black",
                "child4":"White"
            }
        ],
        "Title2":[
            {
                "child5":"Violet",
                "child6":"Purple"
            },
            {
                "child7":"Pink",
                "child8":"Orange"
            }
        ]
    }
}

var addPositions = function() {
    $('.droptrue, .droptrue1').each(function() {
        var position = 0;
        $(this).children().each(function() {
            $(this).data('position', position);
            position++;
        });
    });
};

$(document).ready(function() {
var  treeList = "";
treeList = "<ul id=\"createTree\" class=\"droptrue1 mt1\">";
for(var key in jsonObj){
  //alert("key: " + key + ", value: " + jsonObj[key])
    for (var skey in jsonObj[key]) {
        treeList +=  ("<li class=\"listTree\" id="+skey+"><span class=\"Tbltitle\" >"+skey +"</span><ul class=\"droptrue mt\">");
        for (var sskey in jsonObj[key][skey]){
            for (var ssskey in jsonObj[key][skey][sskey]){
                treeList +=  ("<li class=\"innerList\">"+jsonObj[key][skey][sskey][ssskey]+"</li>");
            }
        }       
        treeList +=  "</ul></li>";
    }
}
treeList += "</ul>";
$('#tree').append(treeList); 
addPositions();
$(".droptrue").sortable({
      connectWith: "ul.mt",
      dropOnEmpty: true,
/*       start: function(event, ui) { 
         var order = [];
         ui.item.closest('ul').children('li').each(function() {
         order.push($(this).data('position'));  

         var x = $(this).not(':first').text();
         var y = $(this).parent().siblings('.Tbltitle').text();
         $("#c2").append(y+"_"+x+"<br />");
        });
        },
*/       stop: function(event, ui) {
         var order = [];
         ui.item.closest('ul').children('li').each(function() {
         order.push($(this).data('position'));
         var c = $(this).text();
         var z = $(this).parent().siblings('.Tbltitle').text();
         $("#cl").append(z+"_"+c+"<br />");
       });
     }
  });
$( "ul.droptrue1").sortable({
      connectWith: "ul.mt1",
      dropOnEmpty: true,
   });
});

fiddle Link: http://jsfiddle.net/thilakar/mwypv/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:05:20+00:00Added an answer on May 24, 2026 at 7:05 am

    Ok, now i understood what you need (i hope)

    var origTitle;
    var origColor;
    $(".droptrue").sortable({
        connectWith: "ul.mt",
        dropOnEmpty: true,
        start: function(event, ui) {
            origColor = ui.item.text();
            origTitle = ui.item.parent().siblings('.Tbltitle').text();
        },
        stop: function(event, ui) {
            var order = [];
    
            ui.item.closest('ul').children('li').each(function() {
                order.push($(this).data('position'));
                var c = $(this).text();
                if (c === origColor) {
                    var z = origTitle;
                } else {
                    var z = $(this).parent().siblings('.Tbltitle').text();
                }
                $("#cl").append(z + "_" + c + "<br />");
            });
        }
    });
    

    Fiddle http://jsfiddle.net/nicolapeluchetti/mwypv/17/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Little help need with jquery sortable. I have a nested list like so: <div
I have a List (.NET) and need to build an indented tree structure. Each
I need to create a tree-like structure in Python. I have a function get(parentId),
I have a binary tree in unordered list that looks like this: <ul> <li>1
I have a tree-like object, managed by Hibernate. The object has a list of
I have a xsl:variable ($features-list) specified in my XSL which contains a tree fragment
I need a tree menu. But instead of a listview where you expand/collapse i
I have a pretty large tree data structure that will get updated (nodes removed
Let’s say I have table/list like this n=3 in this case, but n can
I have a client app that need to show a really big tree (It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.