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
citrinetiger
Posts: 55
Registered: ‎12-04-2012
My Device: Q10
Accepted Solution

Sharing Data in a List

Hi All! 

   I apologize for bringing this up again but I still can not figure out how to SHARE Data within a List Item by clicking a button(not an invoke action item). I think I'm close but as of right now it doesn't work :Helpsmilie: 

 

I found some help topics on the "share anything" code but I can only get it to work in the main.qml, not the List.qml

 

any ideas?

 

thanks

-Ali

 

 

main.qml

import bb.cascades 1.0
import "common"

Page {
    Container {
        Container { // START WORKING CONTAINER

            Label {
                id:goodFruit
                text: "Orange"

            }
            Label {
                id:goodweight
                text: "12oz"
            }
            Button {
                text: "This works!"
                onClicked: {
                    _app.share("I eat " + goodFruit.text + " that weigh " + goodweight.text);
                }
            }
        } // END WORKING CONTAINER
        Container { // START NON-WORKING ListView

            ListView { 
                id: fruitList
                dataModel: XmlDataModel {
                    source: "models/fruitModel.xml"
                }
                listItemComponents: [
                    ListItemComponent {
                        type: "header"
                        Header {

                        }
                    },
                    ListItemComponent {

                        type: "entry"
                        FruitListItem {

                        }
                    }
                ]
            }
        } // END NON-WORKING ListView
    }
}

 FruitListItem:

import bb.system 1.0
import bb.cascades 1.0

Container {
    Label {
        id: badfruit
        text: ListItemData.FRUIT
    }
    Label {
        id: badcolor
        text: ListItemData.COLOR
    }
    Label {
        id: badweight
        text: ListItemData.WEIGHT

    }
    Button {
        text: "Does NOT Work"
        horizontalAlignment: HorizontalAlignment.Center
        onClicked: {
            _app.share("I can NOT share" + ListItemData.Fruit +    ListItemData.COLOR + ListItemData.WEIGHT + "...Do you know why?");
        }
    }

}

 

I get the following error:

asset:///common/FruitListItem.qml:26: ReferenceError: Can't find variable: _app

 

 

Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Sharing Data in a List

Hi,

That's ListItem context issue.

 

Give an id to fruitListItem, for example:

 

                        FruitListItem {
                             id: fruitListItem
                        }

 

Declare a function in ListView:

ListView {
  function getApp() {
    return _app
  }

 Instead of _app.xxx() call fruitListItem.ListItem.view.getApp().xxx()

 

 

 


Andrey Fidrya, @zmeyc on twitter
Developer
citrinetiger
Posts: 55
Registered: ‎12-04-2012
My Device: Q10

Re: Sharing Data in a List

Works!!! Thanks Zmey!!! You tried helping me on the last thread a few months back but I was(am) too fresh to grasp what you were saying. Here is the finished working code:

 

main.qml

import bb.cascades 1.0
import "common"

Page {
    Container {
        Container { // START WORKING CONTAINER

            Label {
                id:goodFruit
                text: "Orange"

            }
            Label {
                id:goodweight
                text: "12oz"
            }
            Button {
                text: "This works!"
                onClicked: {
                    _app.share("I can eat an " + goodFruit.text + " that weighs " + goodweight.text);
                }
            }
        } // END WORKING CONTAINER
        
        Container { // START WORKING ListView

            ListView { 
                id: fruitList
                function getApp() {
                    return _app
                }
                dataModel: XmlDataModel {
                    source: "models/fruitModel.xml"
                }
                listItemComponents: [
                    ListItemComponent {
                        type: "header"
                        Header {

                        }
                    },
                    ListItemComponent {

                        type: "entry"
                        FruitListItem {
                            id: fruitListItem
                        }
                    }
                ]
            }
        } // END WORKING ListView
    }
}

 FruitListItem.qml:

import bb.system 1.0
import bb.cascades 1.0
Container {
    Label {
        id: badfruit
        text: ListItemData.FRUIT
    }
    Label {
        id: badcolor
        text: ListItemData.COLOR
    }
    Label {
        id: badweight
        text: ListItemData.WEIGHT

    }
    Button {
        text: "Does NOT Work"
        horizontalAlignment: HorizontalAlignment.Center
        onClicked: {
            fruitListItem.ListItem.view.getApp().share("I CAN share a " + ListItemData.COLOR + " " + ListItemData.FRUIT + " that weighs" + ListItemData.WEIGHT + "...Do you know why? Because Zmey rocks!");
        }
    }

}

 

and if anyone is reading this and doesn't know how I got "_app" to work as a share component, here is the link to the instructions I followed:

 

https://forrst.com/posts/Adding_Social_Sharing_through_Invocation_to_your-Fmz

 

HUGE thanks again to Zmey!!!

 

-Ali