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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 64
Registered: ‎06-28-2011
My Device: BlackBerry Z10
My Carrier: Bell

DataModel Question

I have a sheet with a textfield. My plan is to enter data on that sheet, hit "add" and then have that data populate on a list.

 

I've read some of the examples and am still slightly confused.

Highlighted
Contributor
Posts: 20
Registered: ‎02-21-2012
My Device: Bold 9900
My Carrier: AT&T

Re: DataModel Question

[ Edited ]

The underlying Page:

 

Page {
    id: viewListPage
    content: ListView {
        id: myListView

        // Associate the list view with the data model that's defined in the
        // attachedObjects list
        dataModel: dataModel
listItemComponents: [ ListItemComponent { type: "item" // Use a standard list item to display the data in the model StandardListItem { title: ListItemData.key1 + " vs. " + ListItemData.key2 } }, // end of ListItemComponent ListItemComponent { type: "header" Header { title: ListItemData } } ] } actions: [ ActionItem { property variant addSheet id: openSheet title: "Open Sheet" ActionBar.placement: ActionBarPlacement.OnBar onTriggered: { addSheet = sheet.createObject(); addSheet.returnData.connect(addData) addSheet.closed.connect(destroySheet) addSheet.open() } function destroySheet() { addSheet.destroy(); } } ] attachedObjects: [ GroupDataModel { id: dataModel sortingKeys: [ "key1", "key2" ] sortedAscending: true grouping: ItemGrouping.ByFullValue }, ComponentDefinition { id: sheet source: "sheet.qml" } ] onCreationCompleted: { // Load SQL data here...maybe? idk what you use } function addData(data1, data2) { var itemData = { "key1": data1,
"key2": data2
} myListView.dataModel.insert(itemData); } }

 

And the "sheet.qml"

 

import bb.cascades 1.0

Page {
    id: sheet
    actionBarVisibility: ChromeVisibility.Hidden
   
    // This signal is connected to the sheet object created in the above code segment
    signal returnData(string data1, string data2)
    
    titleBar: TitleBar {
            visibility: ChromeVisibility.Visible
            dismissAction: ActionItem {
                id: actionDismiss
                title: "Back"
                enabled: true
                onTriggered: {
                    addSheet.close()
                }
            }
            acceptAction: ActionItem {
            id: actionSave
            title: "Save"
            enabled: false
            onTriggered: {
                // Get data, pass it to signal
                returnData(input1.text, input2.text);
                addSheet.close()
            }
        }
    }
    
    // Your stuff
    Container {
         layout: StackLayout {}
         Label {
             id: input1
             text: "Whee"
         }
    }
}
    

 

Contributor
Posts: 20
Registered: ‎02-21-2012
My Device: Bold 9900
My Carrier: AT&T

Re: DataModel Question

The above code is mostly from memory/copy and paste, but if you can fix any small errors, it should lead you in the correct direction.


What the code doesn't do:

 

  • Doesn't let you click on an entry yet
  • Doesn't load data from SQL

 

Developer
Posts: 64
Registered: ‎06-28-2011
My Device: BlackBerry Z10
My Carrier: Bell

Re: DataModel Question

creating the data model is where I get confused. 

 

SQL, JSON, XML...I don't really get the differences and don't know how to create a JSON or SQL.

Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: DataModel Question

If you are adding data that the user has typed into a textfield, then probably the most appropriate is to use an ArrayDataModel - a flat list (no headers) that contains exactly what you want it to

If you want headers in the list, then use GroupDataModel