我的应用程序中有4个页面按顺序 main.qml,login.qml,home.qml和profile.qml。 home.qml有一个listview列出了一些可以在profile.qml中修改的数据。所以每当我从profile.qml回到home.qml时,我需要刷新我的listview。我的main.qml有导航窗格,所以我编写了代码来刷新main.qml上的listview,它确实调用了home.qml中的reloadview函数。我的问题是如果用户第一次登录,那么导航堆栈的所有页面都是 [main.qml,login.qml,home.qml,profile.qml] ,当我从profile.qml弹出重新加载函数被调用但列表视图刷新不会发生在home.qml上。但是,如果已经登录的用户登录,那么导航堆栈的页面为 [main.qml,home.qml,profile.qml] ,当我从profile.qml调用reload函数,listview也会正确刷新。 所以我想如果login.qml存在于堆栈中,那么从main.qml刷新listview会有一些问题,但如果不存在则工作正常。知道我该怎么解决这个问题?或者是否可以在从login.qml推送到home.qml后从堆栈中删除login.qml? 我尝试弹出login.qml然后推送它并且它工作但弹出导致主要。 qml显示,直到它被推回home.qml。非常感谢任何建议。
以下是我的qmls
的示例结构NavigationPane {
id: nav
peekEnabled: false
onPopTransitionEnded: {
if(page.objectName=="newProfilePage")
{
if(!myHomePage)
{
myHomePage=homePageDefenition.createObject();
}
myHomePage.reloadView();
}
page.destroy();
}
Page {
id: mainPage
Container {
//some code
}
onCreationCompleted: {
//Some code and then push to homepage
nav.push(homePageDefenition.createObject());
}
}
}
Page {
id: loginPage
objectName: "loginPage"
Container {
//some code to validate login and push to homepage
var homePage=homePageDefinition.createObject();
nav.push(homePage);
}
}
profilepage.qml
===============
Page {
id: newProfilePage
objectName: "newProfilePage"
Container {
//some code
Button { //a button to pop to home page
id:popButton
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Bottom
onClicked: {
nav.pop();
}
}
}
}
This is my homepage structure
Page {
//some code
function reloadView()
{
homePageScroll.getMyContacts(_settings.getArrayFor("contactList", null));
}
Container {
layout: DockLayout {
}
ScrollView {
id: homePageScroll
Container {
layout: DockLayout {
}
ListView {
//somecode
}
}
function getMyContacts(contacts)
{
//code as shown below
}
}
attachedObjects:[
GroupDataModel {
id: contactsData
sortingKeys: [ "last" ]
grouping: ItemGrouping.None
}
]
}
ImageButton {
id: nextButton
defaultImageSource: "asset:///Images/next_button.png"
pressedImageSource: "asset:///Images/next_button_pressed.png"
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Bottom
onClicked: {
myMenuScreen = profilePageDefinition.createObject();
nav.push(myMenuScreen);
}
}
//在reloadview中调用我的联系人功能
function getMyContacts(contacts)
{
console.log("Contact List:" + contacts); //Contains list of updated contacts and prints correctly
contactsData.clear();
var blockedContacts = _settings.getArrayFor("blockList", null);
console.log("Blocked Contact List:" + blockedContacts);
var addContact = "true";
for (var cntNames in contacts) {
for (var blockedNames in blockedContacts) {
if (contacts[cntNames].toString() == blockedContacts[blockedNames].toString()) {
addContact = "false";
break;
} else {
addContact = "true";
}
}
if (addContact == "true") {
console.log("Inserting:"+contacts[cntNames].toString());
contactsData.insert({
name: contacts[cntNames].toString(),
last: contactsData.size(),
colors:getMyListItemColor(contactsData.size())
})
}
}
var newContacts = new Array();
for (var i = 0; i < contactsData.size(); i ++) {
if (contactsData.data([ i ]).name != '+' ) {
newContacts.push(contactsData.data([ i ]).name);
}
}
_settings.saveArray("contactList", newContacts); //Save the array of contacts in qsettings
console.log("UPdated Contact List:" + newContacts + " Size:"+contactsData.size().toString()); // This prints correctly
}