Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-12117

Add support for JS arrays in ListModel

    XMLWordPrintable

Details

    Description

      It would be very convenient to have a JSON data model to use with QML's list view elements, instead of emulating a model using XMLHttpRequest, regular JavaScript JSON support and ListModel. For example,

      Item {
          ListModel { id: listmodel }
          onCompleted: {
              var xhr = new XMLHttpRequest;
              xhr.open("GET", "http://service.com/api");
              xhr.onreadystatechange = function() {
                  if (xhr.readyState == XMLHttpRequest.DONE) {
                      var a = JSON.parse(xhr.responseText);
                      for (var b in a) {
                          var o = a[b];
                          listmodel.append({name: o.name, url: o.url});
                      }
                  }
              }
              xhr.send();
          }
      } 
      

      Attachments

        1. jsarrayaccess.qml
          1 kB
          Marco Trevisan

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ulherman Ulf Hermann
              hhartz Henrik Hartz (closed Nokia identity) (Inactive)
              Votes:
              86 Vote for this issue
              Watchers:
              41 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes