Wednesday 15 February 2012

sdk - Ubuntu qml how to populate list items from data model -



sdk - Ubuntu qml how to populate list items from data model -

i trying implement medications page using ubuntu sdk. trying info sql lite db , populate list when load page. can if utilize row text , buttons, not if seek utilize listitem.

this works:

page: page { id: drugpage component.oncompleted: { var d = drugs.getdrugs(); drugs.filldruglist(d); } column { id: lstdrugs anchors { top: parent.top left: parent.left right: parent.right bottom: parent.bottom margins: units.gu(2) } spacing: units.gu(2) listmodel { id: mdldrugs } component { id: deldrugs row { spacing: units.gu(6) //width: parent.width text { id: txtdrug text: name } text { id: txtdose text: dose //width: units.gu(4) } text { id: txfrequency text: frequency } } } listview { id: viewdrugs model: mdldrugs delegate: deldrugs height: parent.height width: parent.width } } }

but doesn't work:

page: page { id: drugpage component.oncompleted: { var d = drugs.getdrugs(); drugs.filldruglist(d); } column { id: lstdrugs anchors { top: parent.top left: parent.left right: parent.right bottom: parent.bottom margins: units.gu(2) } spacing: units.gu(2) listmodel { id: mdldrugs } listitem.subtitled { id: deldrugs visible: true width: parent.width height: units.gu(5) text: "drug:" + name + " " + dose subtext: "frequency: " + frequency } listview { id: viewdrugs model: mdldrugs delegate: deldrugs height: parent.height width: parent.width } } }

a list item nowadays in ui not populated data.

the error is: referenceerror: name not defined referenceerror: frequency not defined missing here?

i found reply in qml documentation here: http://developer.ubuntu.com/api/qml/sdk-14.04/qtqml.listmodel/ trick wrap listitem in repeater so. listview not required.

listmodel { id: mdldrugs } repeater { model: mdldrugs listitem.subtitled { text: "drug:" + name + " " + dose subtext: "frequency: " + frequency } }

ubuntu sdk qml

No comments:

Post a Comment