qml - Add property from string to dynamically created ListElement through ListModel.append() -
what correct approach insert dynamic properties dynamically created listelements in listmodel using js? it's seems can't enter variable reference between { } supplying properties, works values.model
lismodel
, function should create listelements
both these properties.
function getreadings(model) { var timestr = "hour_0"; var temp = 11.9; model.append({day: 1, timestr: 11.9}); //error model.append({day: 1, hour_0: 11.9}); //ok! }
i'll appreciate advice.
keep in mind you're working javascript. { } json object, parameter append( ) method.
this worked me:
mousearea { anchors {top: parent.top; right: parent.right} width: 100 height: 100 onclicked: { var mykey = "day" var myvalue = "saturday" var json = { }; json[mykey] = myvalue; listmodel.append(json) } }
Comments
Post a Comment