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
AVPTI
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.

Please use plain text.
Contributor
TheStoof
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"
         }
    }
}
    

 

Please use plain text.
Contributor
TheStoof
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

 

Please use plain text.
Developer
AVPTI
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.

Please use plain text.
Developer
strobejb
Posts: 267
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
Please use plain text.