Is there a best practice to pass JavaScript Date objects to QML List Delegates?
If you have a ListModel like:
And then want to pass the items to the respected section delegate to "render" their view and define the "due" property as sections:Code:ListModel { id: listModel Component.onCompleted: { var now = new Date(); var items = [{title: "test1", due: now, description: "subtitle for item1", id: 0}, {title: "test2", due: now, id: 1}]; for (var i=0, l=items.length; i < l; i++) { listModel.append(items[i]); } } }
"myDate" will return "NaN". The "due" property is typeof string which I guess is the intended way to pass properties to the delegate (?), but neither Date.parse() nor new Date(section) will give you a new date object in the delegate...Code:Component { id: delegate Rectangle { Text { text: { console.log(typeof(section)); console.log("section by delegate: " + section); var myDate = Date.parse(section); console.log("myDate type: " + typeof(myDate)); console.log("myDate: " + myDate.toDateString()); return myDate.toString(); } anchors.left: parent.left font.bold: true } MouseArea { anchors.fill: parent onClicked: console.log("clicked: " + section) } } }



