Info-Dave / marknote

Automatically exported from code.google.com/p/marknote
0 stars 0 forks source link

Need to produce unlimited sub items #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Dear all, 
I need to generate jSon for unlimited sub items as in my example here:
http://jsfiddle.net/ethar1/3qn1j4qx/

What steps will reproduce the problem?
Please check http://jsfiddle.net/ethar1/3qn1j4qx/

What is the expected output? 
{
   "root":[
      {
         "id":"1",
         "SubItems":[
            {
               "test":"First Level",
               "tet":"fff",
               "SubItems":[
                  {
                     "test":"Second Level",
                     "tet":"fff",
                     "SubItems":[
                        {
                           "test":"Third Level",
                           "SubItems":[]
                        }
                     ]
                  }
               ]
            },
            {
               "test":"First Level",
               "tet":"xxxxx",
               "SubItems":[

               ]
            }
         ]
      },
      {
         "id":"2",
         "SubItems":[

         ]
      }
   ]
}
What do you see instead?

{
    "root": [
        {
            "id": "1",
            "SubItems": [
                {
                    "test": "First Level",
                    "tet": "fff",
                    "SubItems": []
                },
                {
                    "test": "First Level",
                    "tet": "xxxxx",
                    "SubItems": []
                }
            ]
        },
        {
            "id": "2",
            "SubItems": []
        }
    ]
}

What version of the product are you using? On what operating system?
the latest version + windows

Please provide any additional information below.

Original issue reported on code.google.com by eth...@gmail.com on 1 Nov 2014 at 11:08

GoogleCodeExporter commented 9 years ago
Could you please help ... 

Original comment by eth...@gmail.com on 1 Nov 2014 at 11:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello Ethar, 
I haven't had time to run through your example completely, but I do notice that 
GeneratejSonSub you're creating a variable, ce, that appears to never get used:

var ce = GeneratejSonSub(elem,  child  );
json[rootName].push(child);

Is that intentional?  

The library doesn't currently have an auto-generate from xml-to-json feature, 
which I have considered adding but have not looked at yet.  If the above tip 
doesn't help I would suggest stepping through the code and seeing if your 
recursive call is doing what you're expecting.

Also, I expect that you will run into a stack overflow eventually with a 
recursive approach if the nesting gets too deep, and to my knowledge ECMA 
currently doesn't support optimized tail recursion.  So an iterative approach 
might suit you better.

Regards
-Rody

Original comment by rody.cunningham@gmail.com on 5 Nov 2014 at 5:10