2013-08-07 4 views
0

안녕하세요 저는 Blackberry 10 cascades 개발을 처음 사용합니다.주어진 XML 모델의 목록보기

아래의 데이터 모델 (assests 폴더에 있음)을 사용하여 목록을 만들고 싶습니다.

Categories.xml 내가 목록 항목으로 만 CategoryNameEn을 표시 할

<?xml version="1.0" encoding="utf-8"?> 
<MasterData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<CategoryList> 
    <Category> 
     <CategoryId>12</CategoryId> 
     <CategoryNameEn>Banks &amp; Investments</CategoryNameEn> 
     <CategoryImageName>banks.png</CategoryImageName> 
     <DisplayOrder>1</DisplayOrder> 
    </Category> 
    <Category> 
     <CategoryId>15</CategoryId> 
     <CategoryNameEn>Car Rental</CategoryNameEn> 
     <CategoryImageName>cars.png</CategoryImageName> 
     <DisplayOrder>2</DisplayOrder> 
    </Category> 
    <Category> 
     <CategoryId>19</CategoryId> 
     <CategoryNameEn>Services</CategoryNameEn> 
     <CategoryImageName>services.png</CategoryImageName> 
     <DisplayOrder>3</DisplayOrder> 
    </Category> 
    <Category> 
     <CategoryId>18</CategoryId> 
     <CategoryNameEn>Real Estate &amp; Constructions</CategoryNameEn> 
     <CategoryImageName>construction.png</CategoryImageName> 
     <DisplayOrder>5</DisplayOrder> 
    </Category> 
    <Category> 
     <CategoryId>2</CategoryId> 
     <CategoryNameEn>Hotels &amp; Apartments</CategoryNameEn> 
     <CategoryImageName>hotels.png</CategoryImageName> 
     <DisplayOrder>7</DisplayOrder> 
    </Category> 
</CategoryList> 
.

main.qml에서 나는 이와 같이 지정했습니다.

// Create a ListView that uses an XML data model 
ListView { 
    dataModel: XmlDataModel { 
     source: "asset:///categories.xml" 
    } 
    // The ListItemComponent defines how "listItem" items should appear. 
    listItemComponents: [ 
     ListItemComponent { 
      type: "Category" //setting the node name 
      Container { 
       preferredWidth: 748 
       preferredHeight: 50 
       background: Color.Blue 

       layout: StackLayout { 
        orientation: LayoutOrientation.LeftToRight 
       } 

       Label { 
        text: ListItemData.CategoryNameEn //setting the node 
        verticalAlignment: VerticalAlignment.Center 
        // Apply a text style to create a title-sized font 
        // with normal weight 
        textStyle { 
         base: SystemDefaults.TextStyles.TitleText 
         fontWeight: FontWeight.Normal 
        } 
       } 
       Container { 
        horizontalAlignment: HorizontalAlignment.Fill 
        verticalAlignment: VerticalAlignment.Center 
        preferredWidth: 50 
        preferredHeight: 50 
        //background: Color.Blue 

        layout: StackLayout { 
         orientation: LayoutOrientation.RightToLeft 
        } 
        // Arrow image 
        ImageView { 
         verticalAlignment: VerticalAlignment.Center 
         translationX: 0 
         translationY: 0 
         imageSource: "asset:///images/arrow.png" 
         rightMargin: 10 
        } 
       } // end of inner Container 
      }//end of outer container 
     } // end of ListItemComponent 
    ]//end of listItemComponents 
}//end of ListView 

출력은 아래 이미지와 같아야합니다.

enter image description here

는 그러나 목록이 비어 있습니다. CategoryNameEn이 목록에 바인딩되어 있지 않습니다. 내 코드에서 무엇이 잘못되었는지 알 수 없습니다. 내 문제를 해결하십시오.

+0

가능한 중복 http://stackoverflow.com/questions/17963643/how 데이터를 목록에있는 항목의 목록보기로 연결하는 것) –

+0

안녕하세요 Kernald 님이 내 코드에서 잘못된 점을 파악하는 데 도움을 주시기 바랍니다. 위의 xml 및 listview를 사용하여 오류를 파악할 수있는 간단한 프로젝트를 만드십시오. 감사합니다. – user2636874

+0

첫 번째 질문에 대답했습니다. –

답변

0

여기에 XML을 수정하지 않은 방법을 설명하는 작은 예제가 있습니다. XML :

<model> 
    <item CategoryNameEn="Banks &amp; Investments" CategoryId="12" CategoryImageName="banks.png" DisplayOrder="1"/> 
    <item CategoryNameEn="Banks &amp; Investments2" CategoryId="33" CategoryImageName="banks2.png" DisplayOrder="2" />  
</model> 

QML :

ListView { 
    dataModel: XmlDataModel { 

     source: "asset:///categories.xml" 
    } 
    // The ListItemComponent defines how "listItem" items should appear. 
    listItemComponents: [ 
     ListItemComponent { 
      type: "item" //setting the node name 
      Container { 
       preferredWidth: 748 
       preferredHeight: 50 
       background: Color.Blue 

       layout: StackLayout { 
        orientation: LayoutOrientation.LeftToRight 
       } 

       Label { 
        text: ListItemData.CategoryNameEn //setting the node 
        verticalAlignment: VerticalAlignment.Center 
        // Apply a text style to create a title-sized font 
        // with normal weight 
        textStyle { 
         base: SystemDefaults.TextStyles.TitleText 
         fontWeight: FontWeight.Normal 
        } 
       } 
       Container { 
        horizontalAlignment: HorizontalAlignment.Fill 
        verticalAlignment: VerticalAlignment.Center 
        preferredWidth: 50 
        preferredHeight: 50 
        //background: Color.Blue 

        layout: StackLayout { 
         orientation: LayoutOrientation.RightToLeft 
        } 
        // Arrow image 
        ImageView { 
         verticalAlignment: VerticalAlignment.Center 
         translationX: 0 
         translationY: 0 
         imageSource: "asset:///images/arrow.png" 
         rightMargin: 10 
        } 
       } // end of inner Container 
      } //end of outer container 
     } // end of ListItemComponent 
    ] //end of listItemComponents 
} //end of ListView 
([폭포에서 목록보기의 목록 항목에 데이터를 바인딩하는 방법]의
+0

위와 같이 모델 (categories.xml)을 변경했습니다. 하지만 지금은 출력이 나오지 않습니다. – user2636874

+0

내가 당신의 일에 준 것. 콘솔에 오류가 있는지 확인하십시오. –

+0

콘솔에이 메시지가 표시됩니다. "Aug 08 05 : 28 : 13.331 com.example.STCDirectory.testDev_TCDirectorye0359adc.253837444 default 9000주의 XmlDataModel : 'asset : ///models/categories.xml'을 소스로 설정할 수 없으며 현재 파일 경로 만 지원됩니다." – user2636874