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
Highlighted
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator
Accepted Solution

How to access ListItemData from itemType function in List View

Hi all,

I have a list view, and in itemtype function, how can I access the ListItemData.accountNameNo? is giving me an error of The function itemType() declared in QML on a ListView must return a string! 

Any help is much appreciated.

Thanks in advance.

 

                            listItemComponents: [
                                ListItemComponent {
                                    type: "accounts"
                                    AccountBox {
                                        id: acc
                                        preferredWidth: 768

                                        accNameNo: ListItemData.accountNameNo
                                        label1: ListItemData.label1
                                        input1: ListItemData.input1
                                        label2: ListItemData.label2
                                        input2: ListItemData.input2
                                    }
                                },
                                ListItemComponent {
                                    type: "fdAccounts"
                                    FDAccountBox {
                                        preferredWidth: 768

                                        accNameNo: ListItemData.accountNameNo
                                        label1: ListItemData.label1
                                        input1: ListItemData.input1
                                    }
                                }
                            ]

                            function itemType(data, indexPath) {

                                if (ListItemType.accountNameNo == "true") {
                                    return "fdAccounts";
                                } else {
                                    return "accounts";
                                }
                            }

 

Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: How to access ListItemData from itemType function in List View

got it fixed by using 

var index= dataModel.data(indexPath);
var name= index.accountNameNo;

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

Re: How to access ListItemData from itemType function in List View

It's even simpler. Since the "data" argument that's being passed in is already the same as what dataModel.data(indexPath) returns, you can simply do "var name = data.accountNameNo".

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!