Как получить доступ к внешним компонентам из listitemcomponents в listview bb10 qml?

Я не могу получить доступ к идентификатору источника данных изнутри ListItemComponent. Может ли кто-нибудь помочь мне в этом?

ListItemComponent {
    type: "item"
    Container {
        id: listviewcontainer
        Container {
            preferredWidth: 768
            layout: StackLayout {
                orientation: LayoutOrientation.LeftToRight
            }
            CustomImageView {
                leftPadding: 10
                rightPadding: 10
                url: ListItemData.from_image
                horizontalAlignment: HorizontalAlignment.Left
                verticalAlignment: VerticalAlignment.Center
            }
            Container {
                preferredWidth: 538
                layout: StackLayout {
                    orientation: LayoutOrientation.TopToBottom
                }
                Container {
                    layout: StackLayout {
                        orientation: LayoutOrientation.LeftToRight
                    }
                    Label {
                        text: ListItemData.from
                        textStyle {
                            base: SystemDefaults.TextStyles.TitleText
                            color: Color.create("#2db6ff")
                        }
                    }
                    ImageView {
                        imageSource: "asset:///Home/img.png"
                        verticalAlignment: VerticalAlignment.Center
                    }
                }//Container
                Label {
                    text: ListItemData.message
                    multiline: true
                    textStyle {
                        base: SystemDefaults.TextStyles.SubtitleText
                    }
                    content {
                        flags: TextContentFlag.Emoticons
                    }
                }
                Label {
                    id: time
                    text: ListItemData.time
                    textStyle {
                        base: SystemDefaults.TextStyles.SmallText
                        color: Color.create("#666666")
                    }
                }
            }//Container
            ImageButton {
                id: delete_btn
                defaultImageSource: "asset:///Icon/delete.png"
                pressedImageSource: "asset:///Icon/delete.png"
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Right
                onClicked: {
                    deleteMessage(ListItemData.tid, ListItemData.uid);
                }
                function deleteMessage(tid, uid) {
                    var request = new XMLHttpRequest()
                    request.onreadystatechange = function() {
                        if (request.readyState == 4) {
                            var mResponse = request.responseText
                            mResponse = JSON.parse(mResponse)
                            var mResponseStatus = mResponse.response[0].receive.status;
                            var mMsg = mResponse.response[0].receive.message;
                            if (mResponseStatus == 1) {
                                msg_DataSource.source = "newurl.com" //   This line not works here..
                                msg_DataSource.load();              //   This line not works here..
                            } else if (mResponseStatus == 0) {
                            }
                        }
                    }// end function
                    request.open("GET", "myurl.com", true);
                    request.send();
                }// deleteMessage
            }//ImageButton
        }//Container
    }//Container
}//ListItemComponent

Здесь я не могу решить следующие две строки

msg_DataSource.source = "newurl.com" 
msg_DataSource.load();  

Я пробовал, как показано ниже, но это тоже не работает

listviewcontainer.ListItem.view.dataModel.message_DataSource.source = "myurl.com";
listviewcontainer.ListItem.view.dataModel.message_DataSource.load();

или это

listviewcontainer.ListItem.view.dataModel.source = "myurl.com"; 
listviewcontainer.ListItem.view.dataModel.load();

person SelvaRaman    schedule 01.02.2013    source источник


Ответы (2)


Еще один простейший способ сохранить объект в глобальной переменной, используя следующий код, который отлично работает со мной.

         onCreationCompleted: {
         Qt.tabbedPane = tabbedPane;
         Qt.homeTab = homeTab;
        }   

Здесь я сохранил tabbedPane в глобальной переменной Qt.tabbedPane при создании страницы Completed. Теперь я могу получить к ней доступ из ListItemComponent с помощью Qt.tabbedPane.

Надеюсь, поможет.

person Rian    schedule 02.04.2013