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
New Member
Posts: 1
Registered: ‎11-20-2012
My Device: playbook
My Carrier: orange

access parent attached objects (SOLVED)

[ Edited ]

Hi,

 

I have a page with a list view object in it. Attached to the page as 'attachedObject' is a custom dialog from another .qml file. I have added as action item to the page that will pop-up the dialog and ask for input. This works and the input is added to a SQL database and displayed as an item in the list.

 

For the list items, I have context actions and one of the actions is 'edit'. For this action I want to use the same dialog that is attached to the page. I can't seem to get it to work as it complains with a reference error: ReferenceError: Can't find variable: editDialog

 

A cut down version of the QML; the error is from the code in red.

 

SOLUTION:

 

http://supportforums.blackberry.com/t5/Cascades-Development/QML-Accessing-variables-defined-outside-...

 

assigned it to a Qt. var


Thanks,

 

John

 

NavigationPane {
    id: navigationPane
    onPopTransitionEnded: page.destroy()
    
    
    Page {
        id: listPage
        content: Container {
            ListView {            
                id: listView
                objectName: "listView"
                dataModel: sqlData
                
                listItemComponents: [
                    ListItemComponent {
                        type: "noDataLabel"
                        Container {
                            layout: StackLayout {
                                orientation: LayoutOrientation.LeftToRight
                            }
                            Label {
                                text: qsTr("No Data found.")
                                textStyle.fontSize: FontSize.XLarge
                            }
                        }
                    },
                    ListItemComponent {
                        type: "listItem"
                        StandardListItem {
                            contextActions: [
                                ActionSet {
                                    actions: [
                                        ActionItem {
                                            title: qsTr ("Open")
                                            imageSource: "asset:///images/icons/open.png"
                                        },                                       
                                        ActionItem {
                                            title: qsTr ("Edit...")
                                            imageSource: "asset:///images/icons/edit.png" 
                                            onTriggered: {
                                                editDialog.open()
                                            }
                                        },                                       
                                        ActionItem {
                                            title: qsTr ("Delete")
                                            imageSource: "asset:///images/icons/delete.png"
                                        }
                                    ]
                                }
                            ]
                        }
                        
                        
                    } //list item
                ]
                function itemType(data, indexPath) {
                    if (data.noData == true) {
                        return "noDataLabel";
                    } else {
                        return "istItem";
                    }
                } // function itemType
            } // List View
            Label {
                id: debugLabel
                text: "debug label text"
            }
            attachedObjects: [
                SqlDataModel {
                    id: sqlData
                    onInitialItemsLoaded: {
                        listView.scrollToItem([
                                0
                            ]);
                    }
                }
            ] // attachedObjects
            
            onCreationCompleted: {
                sqlData.loadData();
            }
        } // container
        actions: [
            ActionItem {
                title: qsTr("New...")
                imageSource: "asset:///images/icons/new.png"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    debugLabel.text = "'New...' action item pressed"
                   
                    editDialog.open()
                }
            }
        ] // actions
    }// Page
   
    attachedObjects: [
        EditDialog {
            id: editDialog
            onOpened: {
                listPage.actionBarVisibility = ChromeVisibility.Hidden
            }
            onClosed: {
                listPage.actionBarVisibility = ChromeVisibility.Default
            }
        }
    ]
}