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
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

ListItemData is data of items in model
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?


AlexeyPanov wrote:
ListItemData is data of items in model

no. ListItemData is the currently selected item, for example in an ActionItem:

DeleteActionItem {
    onTriggered: {                                        
deleteItem(ListItemData); } }

 If you just want to do something on click (without an action) you use onTriggered which delivers the indexPath with it:

onTriggered: {
  var item = dataModel.data(indexPath);
  //do stuff with item
}

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

So , what kind of type of ListItemData is then ?
here
DeleteActionItem {
onTriggered: {
deleteItem(ListItemData);
}
}
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

the item that is selected when the action is triggered
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

yes that i understand. but i need get SongItem object from ListView
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

if you call the delete action while a SongItem object is selected ListItemData will be a SongItem object.

If you click on it onTriggered will be called with the indexPath of a SongItem object in the dataModel.
Calling dataModel.data with the indexPath will return the SongItem object.

In either way you will have the SongItem object. All good?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

onTriggered: {
music_list.clearSelection();
select(indexPath);
var songItem = dataModel.data(indexPath);

look at what i do , but my songItem is var, i should casting to SongItem type ? but how i could do in QML ?
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

javascript is untyped.

why do you call clearSelection followed by select?

in any case, songItem is of type SongItem, you can access its properties.
if you call songItem.label = "my new label" the label property (given it exists) will be set accordingly.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?


simon_hain wrote:

why do you call clearSelection followed by select?

l clear selection on all items at first, previous select clear, then i select current item which i touched on.

 


simon_hain wrote:

in any case, songItem is of type SongItem, you can access its properties.
if you call songItem.label = "my new label" the label property (given it exists) will be set accordingly.

what type is "label" property ?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

as i do not know what properties your object has i just used an invented property (label). you should probably use one that really exists in your code...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter