2012-12-06 123 views
0

如何加載方法,當我點擊從一個qml佈局到其他qml的按鈕?正如我有一個editprofile按鈕,如果我點擊按鈕意味着我想顯示的值,我從web服務得到如何做到這一點?任何人都可以發出一些想法。? 謝謝黑莓10級聯qml方法

+2

你能更精確嗎?沒有得到你的問題。 –

回答

2

你需要實現這個onCreationCompleted方法

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

希望這有助於!。

1

如果我理解你正確,你想要單擊按鈕時執行一個操作。要做到這一點,您可以將onClicked方法添加到QML中的Button對象中。例如:

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

Label { 
    id: myProfileInfo 
    text: "This is my profile" 
    visible: false 
} 
2

聽起來你正在試圖通過從一個web服務檢索從一個QML視圖到另一個數據。在導航窗格中,您可以使用createObject()從.qml文件構建UI屏幕,並將新屏幕(頁面)推送到導航窗格的視圖堆棧,並且您的數據可通過新創建和可見頁面的UI訪問我認爲更具體的描述,以及通常的做法。

爲了傳遞數據,在'profileview'QML頁面的根對象(Page,Container)上聲明一個屬性。然後,在你的按鈕的onClicked()函數的第一個QML文件中,將QML定義中的createObject()的結果賦給變量。然後,您可以使用此變量將數據分配給'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" 
    } 
    ] 
} 

更詳細完整的例子如下:

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": "[email protected]", 
    "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 
    } 
} 
} 

Hopefull幫助你走的時候。此外,在GitHub上這些示例項目可能會幫助:

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

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