Advertisement
Guest User

Untitled

a guest
May 15th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.46 KB | None | 0 0
  1. import QtQuick 2.9
  2. import QtQuick.Controls 2.2
  3.  
  4. Page {
  5.     width: 600
  6.     height: 400
  7.     title: "Locales"
  8.  
  9.     ListModel {
  10.         id: modelLocales
  11.     }
  12.  
  13.     ScrollView {
  14.         anchors.fill: parent
  15.  
  16.  
  17.  
  18.         ListView {
  19.             id: lvLocales
  20.             width: parent.width
  21.             model:  modelLocales
  22.             delegate: ItemDelegate {
  23.                 text: descripcion + "  " + idLocal
  24.                 width: parent.width
  25.                 onClicked: {
  26.  
  27.                     stackView.push( "HabitacionesForm.qml" );
  28.  
  29.                 }
  30.             }
  31.         }
  32.  
  33.         function getData() {
  34.             console.log( "entrando")
  35.             var xmlhttp = new XMLHttpRequest();
  36.             var url = "http://localhost:8080/obtenerLocales";
  37.  
  38.             xmlhttp.onreadystatechange=function() {
  39.                 if (xmlhttp.readyState == XMLHttpRequest.DONE && xmlhttp.status == 200) {
  40.                     myFunction(xmlhttp.responseText);
  41.                 }
  42.             }
  43.             xmlhttp.open("POST", url, true);
  44.             xmlhttp.send();
  45.         }
  46.  
  47.         function myFunction(response) {
  48.             var arr = JSON.parse(response);
  49.  
  50.             for(var i=0; i<arr.listaLocales.length; ++i) {
  51.               lvLocales.model.append( {descripcion: arr.listaLocales[i].descripcion, idLocal: arr.listaLocales[i].idLocal }  )
  52.             }
  53.  
  54.         }
  55.  
  56.         Component.onCompleted: {
  57.             getData( )
  58.         }
  59.  
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement