簡體   English   中英

如何在級聯黑莓手機中將文本字段值從一個qml發送到另一個qml頁面

[英]how to send text field values from one qml to another qml page in cascades blackberry

我是BB級聯開發的新手。 我創建了兩個QML Page 我想將數據從一個QML Page傳遞到另一個。

我想將值phonenumber( id:phonenumber )和金額( id:amount )從mobile.qmlpayment.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"
            }
        ]      
    }
}

下次,請僅發布與問題相關的代碼。 至於您的問題,您可以使用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包含幾個Page

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}
    }
}

所以在這里你可以看到單擊Text中的一個Page小號觸發器改變Text的另一Page

在您的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)

您必須在頁面級別的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);
}

就是這個 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM