2013-02-01 2 views
3

ListItemComponent 내부에서 데이터 소스 ID에 액세스 할 수 없습니다. 누구든지 이것에 관해 나를 도울 수 있습니까? 여기 listview bb10 qml의 listitemcomponents에서 외부 구성 요소에 액세스하는 방법?

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(); 
작동하지 않음

답변

0

데이터 모델을 액세스 가능하게 만드는 가장 간단한 방법은 ListView QML 파일과 같이 정의 된 곳마다 데이터 모델에 property alias을 선언하는 것입니다. 그러면 property alias에서 QML의 최상위 구성 요소에서 데이터 모델에 액세스 할 수 있습니다. 실제로 QML의 다른 곳에서나 데이터 모델에 대한 전역 참조를 제공합니다. 예를 들어

하면 데이터 모델이 다음은이 같은 속성 별칭을 만들 수 있습니다 정의 된 QML 파일에서 msg_DataSource를 호출하는 경우 : 당신의 ListItemComponent deleteMessage 기능에 다음

property alias myDataModel: msg_DataSource 

을 수행 할 수 있습니다

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

참고 : 난 당신이 또한 신호와 슬롯을 사용하여 더 우아한 방법으로이 작업을 수행 할 수있는 확신하지만,이 방법은 빨리해야하고 전자 같은 myDataModel를 사용 이해하기 쉬워.

1

나에게 잘 작동하는 다음 코드를 사용하여 개체를 전역 변수에 저장하는 또 다른 가장 간단한 방법입니다.

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

여기에 내가 할 수 Qt.tabbedPane를 사용하여 ListItemComponent에서 액세스 할 수 Completed.Now 페이지 생성에 전역 변수 Qt.tabbedPane에 탭 구획을 저장.

희망이 있습니다.