简体   繁体   English

如何从级联黑莓中的listview获取价值

[英]how to get value from listview in cascade Blackberry

Well I am just trying to get the value from the list-view on selection and pass it to the next screen(page). 好吧,我只是想从选择列表视图中获取值并将其传递到下一个屏幕(页面)。 But I am unable to do as it shows error like 但我无法做,因为它显示错误

asset:///main.qml:25: TypeError: Result of expression 'dataModel.model' [undefined] is not a function. asset:///main.qml:25:TypeError:表达式'dataModel.model'[undefined]的结果不是函数。

My following piece of code is as follows 我的下面一段代码如下

This code is of my main.qml 这段代码是我的main.qml

NavigationPane 
{
id:navi
Page 
{
    Container
    {
         background: Color.Transparent
         topMargin:2.0

         TextField {
             id: lb1
             text:""
         }

         ListView 
         {
            topMargin: 2.0
            dataModel: XmlDataModel { source: "model.xml" }
            onTriggered: {
                console.log("onTriggered");

                // Retrieve the selected item
                var selectedItem = dataModel.data(indexPath);
                    lb1.text = selectedItem.status;

                pushed.lb2.text="You Selected :" + lb1.text;
                navi.push(pushed)
                }

           }
         }

}

attachedObjects: [
    Page2 {
        id: pushed
        }
]

}   

This code is of my second page Page2.qml, where I want to retrieve the info from the main.qml 这段代码是我的第二页Page2.qml,我想从main.qml中检索信息

import bb.cascades 1.0

Page {
property alias lb2: lb2
Container {
    horizontalAlignment: HorizontalAlignment.Center

    Label {
        id:lb2
        horizontalAlignment: HorizontalAlignment.Center
        verticalAlignment: VerticalAlignment.Center
        text: "You Selected :" + lb1
    }

  }
}

I am new to this development. 我是这个发展的新手。

You can get current item of the model on Trigger like as below code.. 您可以在Trigger上获取模型的当前项,如下面的代码所示。

onTriggered: {
      var selectedItem = dataModel.data(indexPath);
      textField.text = selectedItem.status;
}

You can learn more from Responding to selection . 您可以从响应选择中了解更多信息。

Updated: 更新:

You have to set Alias for pass data from one page to another page. 您必须将传递数据的别名从一个页面设置为另一个页面。

Some problem in your error.. 你错误中的一些问题......

1)Remove text in below line in OnTriggerd. 1)删除OnTriggerd中下面一行的文本。

pushed.lb2 ="You Selected :" + lb1.text;

2) Set Alias properly 2)正确设置别名

property alias lb2: lb2.text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM