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
Bluenoser
Posts: 267
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook
Accepted Solution

GroupDataModel Updating Data

Hi,

 

  I have a ListView that has a GroupDataModel which reads a JSON file. I load the file and everything is fine. The data is grouped into three sections. The data can have one to three of the sections (type = 1 to 3)  filled in. I am attempting to copy data from the manditory section (type = 3) and copy it to the one of the other sections. In this case from type 2 to type 1. I check to see that type 2 doesn't already exist in type 1. It works (mostly), but sometimes when I copy a type 2 to type 1, the data gets modified correctly, but it pushes it to the top of the ListView and makes a fourth group, but the data is right and the group header is also correct. Is this a bug? Can someone please take a look at my code and see if this is a coding issue or a bug?

 

                                    ActionItem {
                                        id: favoriteActionItem
                                        title: coursesListItem.ListItem.view.getActionItemTitle("favorite", ListItemData)
                                        imageSource: coursesListItem.ListItem.view.getActionItemImageSource("favorite", ListItemData)
                                        enabled: coursesListItem.ListItem.view.getActionItemEnabled("favorite", ListItemData)
                                        onTriggered: {
                                            if (ListItemData.type == 1) {
                                                // If course is a favorite, then remove.
                                                coursesListItem.ListItem.view.favoriteAction(QueryOp.FavoriteRemove, ListItemData.courseid)
                                                // Handle ListView updating
                                                coursesListItem.ListItem.view.dataModel.remove(ListItemData);
                                            } else {
                                                // Add course as a favorite.
                                                coursesListItem.ListItem.view.favoriteAction(QueryOp.FavoriteAdd, ListItemData.courseid)
                                                // Handle ListView updating
                                                // * Check that selected list item is not already a favorite by setting the sort keys
                                                var searchKeys = [ "1", "0000", ListItemData.name ];
                                                // * Try and find the data in the favorites and get the QVariantList results
                                                var searchResults = coursesListItem.ListItem.view.dataModel.find(searchKeys);
                                                coursesListItem.ListItem.view.setindexPathResults("searchResults", searchResults); // Display
                                                // * If the QVariantList has no records, then add the modified data
                                                if (searchResults.length < 1) {
                                                    var favoriteListItem = ListItemData;
                                                    favoriteListItem.type = 1;
                                                    favoriteListItem.distsort = '0000';
                                                    favoriteListItem.distance = '';
                                                    coursesListItem.ListItem.view.dataModel.insert(favoriteListItem);
                                                }
                                            }
                                        }
                                    }

 Thanks in advance.

Please use plain text.
Developer
Bluenoser
Posts: 267
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: GroupDataModel Updating Data

Got it figured out.  I needed to have my search keys and changes to be strings.

 

                                    ActionItem {
                                        id: favoriteActionItem
                                        title: coursesListItem.ListItem.view.getActionItemTitle("favorite", ListItemData)
                                        imageSource: coursesListItem.ListItem.view.getActionItemImageSource("favorite", ListItemData)
                                        enabled: coursesListItem.ListItem.view.getActionItemEnabled("favorite", ListItemData)
                                        onTriggered: {
                                            if (ListItemData.type == 1) {
                                                // If course is a favorite, then remove.
                                                coursesListItem.ListItem.view.favoriteAction(QueryOp.FavoriteRemove, ListItemData.courseid)
                                                // Handle ListView updating
                                                coursesListItem.ListItem.view.dataModel.remove(ListItemData);
                                            } else {
                                                // Add course as a favorite.
                                                coursesListItem.ListItem.view.favoriteAction(QueryOp.FavoriteAdd, ListItemData.courseid)
                                                // Handle ListView updating
                                                // * Check that selected list item is not already a favorite by setting the sort keys
                                                var searchKeys = [ '1', '0000', ListItemData.name ];
                                                // * Try and find the data in the favorites and get the QVariantList results
                                                var searchResults = coursesListItem.ListItem.view.dataModel.find(searchKeys);
                                                // * If the QVariantList has no records, then add the modified data
                                                if (searchResults.length < 1) {
                                                    var favoriteListItem = ListItemData;
                                                    favoriteListItem.type = '1';
                                                    favoriteListItem.distsort = '0000';
                                                    favoriteListItem.distance = '';
                                                    coursesListItem.ListItem.view.dataModel.insert(favoriteListItem);
                                                }
                                            }
                                        }
                                    }

 

Please use plain text.