Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 88
Registered: ‎01-05-2013
My Device: BB10
My Carrier: Viettel
Accepted Solution

Multi value ArrayDataModel in QML

I have the ArrayDataModel:

 

 ArrayDataModel {
            id: arrayModel
            

        },

 

 

 

DataSource:

        DataSource {
            id: subListDataSource
            source: "data/xPlayer.db"
            query: "SELECT * FROM song_data WHERE album ='" + subListPage.keyWord + "'";
            
            onDataLoaded: {
                subListDataModel.clear();
                for (var i = 0; i < data.length; ++ i) {                  
                    arrayModel.append(data[i])
                }

            }

        }

 and ListView:

  ListView {
            dataModel: subListDataModel

            listItemComponents: [
                ListItemComponent {
                    type: "item"
                    StandardListItem {
                        title: ListItemData.title
                        status: ListItemData.album

                    }

                }
            ]
      }

 the xPlayer.db file is a database store song_data table that include song info (album, artist, title)

 

I implement this code but list view seem not work properly, it only show album property in the listview title???

Can I have an multi property array data model?

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Multi value ArrayDataModel in QML

Implement a listType() routine on the ListView, something like this:

                function itemType(data, indexPath) {
                    return 'item';
                }

Without that, it has no way to know that the type of the items being returned from the DataModel should match the "item" type you specified in the ListItemComponent.

 

Alternatively, change the ListItemComponent to say just type: "" since that's basically the default item type.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Multi value ArrayDataModel in QML

I think you have to add the record of your select query as maps to your ArrayDataModel to be able to access more than one field. 

Developer
Posts: 88
Registered: ‎01-05-2013
My Device: BB10
My Carrier: Viettel

Re: Multi value ArrayDataModel in QML

Thank you very much but. I delete "item" and it worked for me but I still don't really understand the problem. Can you explain more specificly? especial in

                function itemType(data, indexPath) {
                    return 'item';
                }

 

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Multi value ArrayDataModel in QML

Did you read the ListView documentation? It describes how that itemType() routine functions. Basically, without it, you're getting a default item type of "" and not an item type of "item". How would the ListView know which ListItemComponent to pick when you've labelled your only one as being type: "item" ?

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!