title: QML: How to create a nested model with javascript?
body: <p>My goal is to take json data that contains nested comments(like on hackernews or reddit) and display it in my qml app.
  I have found how to create a tree view from a nested model:
  <a href="http://qt-project.org/forums/viewthread/30521" rel="nofollow">http://qt-project.org/forums/viewthread/30521</a></p>
  
  <p>And now I'm trying to figure out how to build a nested model using javascript.
  I need something like this:
  </p>
  
  <pre><code>ListModel {
              id: treemodel
              ListElement { text: "Level 1, Node 1" }
              ListElement {
                  text: "Level 1, Node 2"
                  children: [
                      ListElement { text: "Level 2, Node 1"
                          children: [
                              ListElement { text: "Level 3, Node 1" }
                          ]
                      },
                      ListElement { text: "Level 2, Node 2" }
                  ]
              }
              ListElement { text: "Level 1, Node 3" }
          }
  </code></pre>
  
  
  
  <p>I can add top level elements to the model like so:</p>
  
  
  
  <pre><code>        function createCommentsModel() {
              var i = 0;
              for (i = 0; i &lt; 5; i++) {
                  treemodel.append ({
                      text: "Level 1, Node " + i
                  });
              }
          }
  </code></pre>
  
  
  
  <p>But how do I add children to these elements(and subchildren to these children, etc, recursively)?</p>