【问题标题】:how to send text field values from one qml to another qml page in cascades blackberry如何在级联黑莓中将文本字段值从一个qml发送到另一个qml页面
【发布时间】:2015-07-23 05:07:15
【问题描述】:

我是 BB 级联开发的新手。我创建了两个 QML Pages。我想将数据从一个 QML Page 传递到另一个。

我想将值 phonenumber(id:phonenumber) 和金额 (id:amount) 从 mobile.qml 传递到 payment.qml

请任何人帮助我。提前谢谢你。

Mobile.qml:

import bb.cascades 1.4
import bb.data 1.0

Page {
    onCreationCompleted: {
        getData()
        getCircle()
    }

    Container {   
        background: backgroundPaint.imagePaint
        attachedObjects: [
            ImagePaintDefinition {
                id: backgroundPaint
                imageSource: "asset:///images/background.png"
            }
        ]

        TextField {
            id:phonenumber
            hintText: "Enter Phone Number"
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            topMargin: ui.du(3)

            // On text change the label text is updated.           
            input
            {
                keyLayout: KeyLayout.Text
            }
        }

        TextField {
            id:amount
            hintText: "Enter Amount"
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            topMargin: ui.du(3)

            // On text change the label text is updated. 
            input
            {
                keyLayout: KeyLayout.Text
            }
        }

        Button {
            id: newButton
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            topMargin: ui.du(3)
            text: "Recharge"
            appearance: ControlAppearance.Primary
            color: Color.create("#F93249")
            onClicked: {
                var blogpage = goToWebView.createObject();
                navigationPane.push(blogpage);
            }
            attachedObjects: ComponentDefinition {
                id: goToWebView
                source: "payment.qml"
            }         
        }   
    }

    attachedObjects: [
        ComponentDefinition {
            id: newOptionDef
            Option {}
        }
    ] 
}

payment.qml:

import bb.cascades 1.4

Page {
    Container {      
        background: backgroundPaint.imagePaint

        attachedObjects: [
            ImagePaintDefinition {
                id: backgroundPaint
                imageSource: "asset:///images/background.png"
            }
        ]      
    }
}

【问题讨论】:

  • 谁能帮帮我!
  • 任何人帮助我,我没有得到任何解决方案:)

标签: qt blackberry qml blackberry-10 blackberry-cascades


【解决方案1】:

下次请只发布与问题相关的代码。至于您的问题,您可以使用parent 作为代理从另一项访问一项。 例如,假设我们有一个组件:

Page.qml

import QtQuick 2.4
import QtQuick.Controls 1.2

Item {
    id:page
    width: 200
    height: 200
    property int callee
    function func() {
        txt.text = txt.text + " (changed)"
    }

    Text {
        id: txt
        anchors.centerIn: parent
        text: "click me"
        MouseArea {
            anchors.fill: parent
            onClicked: {
                page.parent.proxyFunction(page.callee);
            }
        }
    }
}

所以Item 包含几个Pages:

import QtQuick 2.4
import QtQuick.Window 2.0

Window {
    width: 400
    height: 200

    Row {
        anchors.fill: parent
        function proxyFunction(page) {
            children[page].func();
        }
        Page {callee: 1}
        Page {callee: 0}
    }
}

所以在这里你可以看到在Pages 之一中单击Text 会触发在另一个Page 中更改Text

【讨论】:

  • 我编辑了我的帖子。对不起,我不明白你的代码。我对bb很陌生。你能编辑我的代码吗?我需要将那些文本字段(id:phonenumber 和 id:amount)文本发送到 payment qml。
【解决方案2】:

在您的Page 中添加以下行:

 import bb.cascades 1.4
 import bb.data 1.0
 Page {

    id: mobilePage // ADD THIS
    property string m_amount // ADD THIS
    property string m_phoneNumber // ADD THIS

    // the rest of the code

    onClicked: { // Buttons onClick
        mobilePage.m_amount = amount.text             // ADD THIS
        mobilePage.m_phoneNumber = phonenumber.text   // ADD THIS
        var blogpage = goToWebView.createObject()
        navigationPane.push(blogpage)
    }
}

现在在payment.qml 你可以使用这个:

console.log(mobilePage.m_amount)
console.log(mobilePage.m_phoneNumber)

【讨论】:

  • 我试过你的代码。但它显示 Error: Invalid write to global property "m_amount" in mobile.qml page
  • 添加了您设置值的移动页面。立即尝试
【解决方案3】:

您必须在页面级别的 payment.qml 中创建一个属性。

Page{
    Id: payment
    Properly string phonenumber;
    Properly string amount;
    Container{
        Label{
            Id: lblphonenumber
            text: phonenumber 
       } 
       Label{
           Id: lblamout
           text: amount
       } 

}

在你的 main.qml 中你必须这样做:

onClicked: {
    var blogpage = goToWebView.createObject();
    blogpage.phonenumber = yourvalue;
    blogpage.amount = yourvalue;
    navigationPane.push(blogpage);
}

就是这样:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    相关资源
    最近更新 更多