0

当我单击从一个 qml 布局到另一个 qml 的按钮时,如何加载方法?如果我单击按钮,则有一个编辑配置文件按钮意味着我想显示值,我从网络服务获得如何做到这一点?任何人都可以发送一些想法。?谢谢

4

3 回答 3

2

你需要实现这个 onCreationCompleted 方法

    onCreationCompleted: {
   // call the function, that you need to show first
   // first_display()
   }

希望这可以帮助。!!!

于 2013-03-18T07:12:56.920 回答
2

听起来您正试图将从 Web 服务检索到的数据从一个 QML 视图传递到另一个。导航窗格,您可以在其中使用createObject().qml 文件构建 UI 屏幕并将新屏幕(页面)推送到导航窗格的视图堆栈上,您的数据可访问新创建的可见页面的 UI 是我认为更具体的描述,以及执行此操作的常用方法。

为了传递您的数据,请在“profileview”QML 页面的根对象(页面、容器)上声明一个属性。然后,在按钮onClicked()函数的第一个 QML 文件中createObject(),将 QML 定义的结果分配给变量。然后,您可以使用此变量将您的数据分配给“profileview”页面上的属性。你的按钮看起来像这样:

// Assume you have a Navigation Pane called navPane
// You also have to define a component for your QML file
Button {
  text: "View profile"
  onClicked: {
    var profilePage = profileDefinition.createObject();
    profilePage.myData = webserviceData;
    navPane.push(profilePage);
  }
  attachedObjects: [
    ComponentDefinition {
      id: profileDefinition
      source: "profilePage.qml"
    }
  ]
}

下面是基于 Navigation Pane Cascades 示例项目的更详细的完整示例:

main.qml

// Navigation pane project template
import bb.cascades 1.0

NavigationPane {
id: navPane

// This property holds and tracks the created profile page
property Page profilePage

/* This property holds some sample webservice data, in practice 
 * you would load this from the webservice
 */
property variant webserviceData: {
    "name": "John Doe",
    "email": "john.doe@stackoverflow.com",
    "twitter": "@johndoe"
}
Page {
    // page with a button to display profile
    Container {
        layout: DockLayout {
        }
        Label {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Top
            text: webserviceData.name
        }
        Button {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            text: qsTr("Show Profile")
            onClicked: {
                // show detail page when the button is clicked
                profilePage = profileDefinition.createObject();
                profilePage.myProfileData = webserviceData;
                navPane.push(profilePage);
            }
            attachedObjects: [
                ComponentDefinition {
                    id: profileDefinition
                    source: "profilePage.qml"
                }
            ]
        }
    }
}
onPopTransitionEnded: {
    // Clean up any pages that have been popped, to avoid memory leaks
    if (profilePage == page) {
        page.destroy();
    }
}
}

profilePage.qml

// Navigation pane project template
import bb.cascades 1.0

Page {

/* Our data property
 * Note: A variant is a QVariant Qt type, so it can easily handle different 
 * data types, in our case it is a map.
 * Without the braces to denote that it is an object you will get a TypeError
 * from QML at runtime 
 */
property variant myProfileData: { /*empty object*/ }

// page with profile details
paneProperties: NavigationPaneProperties {
    backButton: ActionItem {
        onTriggered: {
            // Pop this page off the stack and go back
            navPane.pop();
        }
    }
}
Container {
    Label {
        text: qsTr("Profile Page")
        horizontalAlignment: HorizontalAlignment.Center
        textStyle {
            base: SystemDefaults.TextStyles.TitleText
            color: Color.Blue
        }
    }
    Label {
        text: "Name:"
        horizontalAlignment: HorizontalAlignment.Left
    }
    TextField {
        text: myProfileData.name
        horizontalAlignment: HorizontalAlignment.Center
    }
    Label {
        text: "Email:"
        horizontalAlignment: HorizontalAlignment.Left
    }
    TextField {
        text: myProfileData.email
        horizontalAlignment: HorizontalAlignment.Center
    }
    Label {
        text: "Twitter:"
        horizontalAlignment: HorizontalAlignment.Left
    }
    TextField {
        text: myProfileData.twitter
        horizontalAlignment: HorizontalAlignment.Center
    }
}
}

希望这可以帮助您继续前进。此外,GitHub 上的这些示例项目可能会有所帮助:

https://github.com/blackberry/Cascades-Samples/tree/master/quotes

https://github.com/blackberry/Cascades-Samples/tree/master/weatherguesser

于 2013-01-23T02:56:44.187 回答
1

如果我理解正确,您希望在单击按钮时执行操作。为此,您可以将该onClicked方法添加到ButtonQML 中的对象中。例子:

Button {
    text: "View profile"
    onClicked: {
        myProfileInfo.visible = true;
    }
}

Label {
    id: myProfileInfo
    text: "This is my profile"
    visible: false
}
于 2012-12-10T22:59:15.310 回答