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

  • Home
  • SEARCH
  • 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 7936973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:23:05+00:00 2026-06-03T22:23:05+00:00

I am using this example using drag and drop from this site: I am

  • 0

I am using this example using drag and drop from this site:

I am creating containers using Dnd item types example in the same page. Like this;

Source container

var catalog = new dojo.dnd.Source("catalogNode", {
    accept: ["inStock,outOfStock"]
});
catalog.insertNodes(false, [
    { data: "Wrist watch",        type: ["inStock"] },
    { data: "Life jacket",        type: ["inStock"] },
    { data: "Toy bulldozer",      type: ["inStock"] },
    { data: "Vintage microphone", type: ["outOfStock"] },
    { data: "TIE fighter",        type: ["outOfStock"] },
    { data: "Apples",             type: ["inStock"] },
    { data: "Bananas",            type: ["inStock"] },
    { data: "Tomatoes",           type: ["outOfStock"] },
    { data: "Bread",              type: ["inStock"] }
]);
catalog.forInItems(function(item, id, map){
    // set up CSS classes for inStock and outOfStock
    dojo.addClass(id, item.type[0]);
});

Target container

var wishlist = new dojo.dnd.Source("wishlistNode", {
    accept: ["inStock","outOfStock"]
});

here what I am doing;

dojo.connect(dojo.byId('JsonBtn'), 'onclick', function() {
        var catalogNode = document.getElementById("catalogNode");
        //Get all nodes in the assignRoleListContainer
        var container2 = catalogNode.getAllNodes();
        var results="";
        var catalog_arr = [];
        var len = container2.length;
        for(var i=0;i<len;i++){
            results = catalogNode.childNodes[i].childNodes[0].nodeValue;
            catalog_arr.push(results);
        }
        //Json
        var myJSON2 = "";
        myJSON2 = JSON.stringify({catalog: catalog_arr});
    });

I managed to convert all data in Json;

{"catalog":["Life jacket","Toy bulldozer","Wrist watch","Apples","Bananas","Bread","Tomatoes","Vintage microphone","TIE fighter"]} 

But now I want to convert the items to json, but with respect to their types, e.g.

If type inStock

{"inStock":["Life jacket","Toy bulldozer","Wrist watch","Apples","Bananas","Bread"]}

If type outOfStock

{"outOfStock":["Tomatoes","Vintage microphone","TIE fighter"]}

Any suggestion?

  • 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-06-03T22:23:06+00:00Added an answer on June 3, 2026 at 10:23 pm

    Source container

    var catalog = new dojo.dnd.Source("catalogNode", {
        accept: ["inStock","outOfStock"]
    });
    catalog.insertNodes(false, [
        { data: "Wrist watch",        type: ["inStock"] },
        { data: "Life jacket",        type: ["inStock"] },
        { data: "Toy bulldozer",      type: ["inStock"] },
        { data: "Vintage microphone", type: ["outOfStock"] },
        { data: "TIE fighter",        type: ["outOfStock"] },
        { data: "Apples",             type: ["inStock"] },
        { data: "Bananas",            type: ["inStock"] },
        { data: "Tomatoes",           type: ["outOfStock"] },
        { data: "Bread",              type: ["inStock"] }
    ]);
    catalog.forInItems(function(item, id, map){
        // set up CSS classes for inStock and outOfStock
        dojo.addClass(id, item.type[0]);
    });
    

    Target container

    var wishlist = new dojo.dnd.Source("wishlistNode", {
        accept: ["inStock","outOfStock"]
    });
    

    Button with Id=JsonBtn, and onClick event, convert data in target container to json

    dojo.connect(dojo.byId('JsonBtn'), 'onclick', function() {
        var target_container = wishlistNode.getAllNodes();
        var inStock_arr = [];
        var outOfStock_arr = [];
        for(var i=0;i<target_container.length;i++){
            if (hasClass("inStock", target_container[i].classList)){
                var inStock_results = target_container[i].childNodes[0].nodeValue;
                inStock_arr.push(inStock_results);                              
            }                           
            else if(hasClass("outOfStock", target_container[i].classList)){
                var permissions_results = target_container[i].childNodes[0].nodeValue;
                outOfStock_arr.push(outOfStock_results);
            }
        }
        var result={};
        result["inStock"]=inStock_arr;
        result["outOfStock"]=outOfStock_arr;
        alert(JSON.stringify(result));
    });
    

    Check classList function

    function hasClass(className, classList){
        for (var i=0; i<classList.length; i++){
            if(classList[i]==className){
                return true;
            }               
        }
        return false;
    }
    

    Output: (This output also fine for me)

    {
     "inStock":[
        "Wrist watch", "Life jacket", "Toy bulldozer", "Apples", "Bananas", "Bread"],
     "outOfStock":[
        "Vintage microphone", "TIE fighter", "Tomatoes"]
    }
    

    First of all, thanks to FireFox team for their “FireBug”. It helps a lot in debugging and programming and without it its very difficult for me to find the solution.

    And if there any explanation needed, I am happy to help.

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

Sidebar

Related Questions

From this example http://www.senchafiddle.com/#dPZn0 This displays a first panel, then a second one... using
I'm using something very similar to this: http://jqueryui.com/demos/droppable/#shopping-cart Currently when I drag an item
I'm using CommonsGuy's drag n drop example and I am basically trying to integrate
I have a sortable like the 2nd example on this page: http://jqueryui.com/demos/sortable/items.html The sortable
I am using the basic Drag and Drop example of Sencha and modifying it.
I'm using this plugin: http://www.jeremymartin.name/projects.php?project=kwicks And my code follows this example: http://www.jeremymartin.name/examples/kwicks.php?example=7 I'm using
I have an array list of objects and I am using this example to
I'm using the apache POI to read Word documents. I'm using this example as
Just using this as an example... Here are the columns in my UserProfile table:
I have looked at this example using php and GD to piecewise-render a spiral

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.