[英]Delegate an array in QML
I have an array, which is presented like: one,two,three; 我有一个数组,表示为:一,二,三; when printing them in console.
在控制台中打印它们时。 I want to delegate these as a ListView but don't know how?
我想将它们委托为ListView,但不知道如何?
So I kind of did what Amit told me to, but I should have been more specific since the real issue I had was the loop, which I've now resolved. 所以我做了Amit告诉我的事情,但是我应该更具体一些,因为真正的问题是循环,现在我已经解决了。
I just created a ListModel with just an ID. 我刚刚创建了一个仅具有ID的ListModel。 Then I ran the array trough a function from forEach, which added each of the items in the array to the already created ListModel.
然后,我通过forEach的一个函数运行该数组,该函数将数组中的每个项目添加到已经创建的ListModel中。 Done!
完成!
// create the listmodel to use
ListModel {
id: playlistModel
}
// function that adds each playlist in the listmodel to show it in the app
function addtoPlaylistModel(element,index,array) {
console.debug("Debug: Playlist #" + index + " = " + element);
playlistModel.append({"id": index, "name": element});
}
// get playlists in an array
var playlist = playlist1,playlist2,playlist3
console.debug("Debug: Playlists: "+playlist) //debug
playlist.forEach(addtoPlaylistModel) // send each item on playlist array to the model to show it
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.