Pregunta

I have a list view containing 5 items and I want each item to navigate to a different page when tapped. All I want to happen is to navigate to a different page NOT pass any data (as many tutorials keep saying) so how this be achieved. Examples also would be hugely appreciated.

Thanks

QML

import bb.cascades 1.2

NavigationPane {
    Page {
        titleBar: TitleBar {
            title: "Hello World"

        }
        Container {
            //Todo: fill me with QML
            ListView {
                dataModel: XmlDataModel {source: "list.xml"}
                listItemComponents: [
                    ListItemComponent {
                        type: "item"
                        StandardListItem {
                            title: ListItemData.title
                            description: ListItemData.text
                        }
                    }
                ]

            }
        }
    }
}

XML

<root>
    <item title="Item 1"    file="item1.qml"/>
    <item title="Item 2"    file="item2.qml"/>
    <item title="Item 3"    file="item3.qml"/>
    <item title="Item 4"    file="item4.qml"/>   
    <item title="Item 5"    file="item5.qml"/> 
</root>
¿Fue útil?

Solución

First you need to catch that click, so use

onTriggered: {
    //use this to get data from your click
    var myData = dataModel.data(indexPath);         
}

Now myData will have title and file stored. But you can't (at least not that I know of) open QML without defining it first. So use this:

 attachedObjects: [
    ComponentDefinition {
         id: mitem1
         source: item1.qml
    },
    ComponentDefinition {
         id: mitem2
         source: item2.qml
    } //etc
 ]

And then call something like this (you can get file name from myData.file so use that to call the correct ID) from onTriggered

navigationPane.push(mitem1.createObject());

oh, and you need to set up ID for NavigationPane (id:navigationPane)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top