02-20-2013 08:40 PM
How come when I have my .XML directly in my ListView, all the list items display properly, but if I add the data to a data source, it doesn't.
Example below because I can't explain this very well.
ListView {
dataModel: XmlDataModel {
source: "hills.xml"
}
listItemComponents: [
ListItemComponent {
type: "listItem"
StandardListItem {
title: ListItemData.skiHill
}
},
ListItemComponent {
type: "header"
Header {
title: ListItemData.key
touchPropagationMode: TouchPropagationMode.None
}
}Vs.
ListView {
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "listItem"
StandardListItem {
title: ListItemData.skiHill
}
},
ListItemComponent {
type: "header"
Header {
title: ListItemData.key
touchPropagationMode: TouchPropagationMode.None
}
}
...
attachedObjects: [
GroupDataModel {
id: dataModel
sortingKeys: [
"skiHill"
]
},
DataSource {
id: dataSource
source: "hills.xml"
query: "/root/listItem"
onDataLoaded: {
dataModel.insertList(data);
}
}
On the 2nd of two different types of lists, the list item displays info from a different part of my XML, not the ski hill name.
Solved! Go to Solution.
02-20-2013 08:49 PM
02-20-2013 08:53 PM
XML
<header key="A"/> <listItem skiHill="Asessippi Ski Area" picture="Asessippi.jpg" phone="204-564-2000" website="www.asessippi.com" street="" city="Inglis MB" monfriHours="9am-4:30pm (8pm Wed/Fri)" satHours="9am-8pm" sunHours="9am-4:30pm" childLift="Child (6-12)" seniorLift="Youth" studentLift="Student/Senior" adultLift="Adult (18+)" adultDayLift="$48" seniorDayLift="$40.80" childDayLift="$36.70" studentDayLift="$43.20" adultNightLift="$36" seniorNightLift="$30.60" childNightLift="$27.50" studentNightLift="$36" adultRental="All Ages" childRental="Pre School" adultDayRental="$32" childDayRental="$28.80" adultNightRental="$27" childNightRental="$24.50" dayLift="Full Day" nightLift="Night(3pm-8pm)" greenCircle="8" blueSquare="8" blackDiamond="5" doubleblackDiamond="0" verticalDrop="N/A" gondola="0" doubleAmount="0" fourSeater="1" threeSeater="1" tBar="" ropeTow="0" snowPark="Yes" snowfall="45cm"/>
And what happens
It seems to pull data from the "adultDayLift" part of the XML.
Like I said, when I don't use GroupDataModel, it works fine.
02-20-2013 09:00 PM
02-20-2013 09:13 PM
I'm new and XML data was used in the examples I read, so it stuck to me.
I was able to get the items to be named properly, but in the process lost the headers. Now the headers appear as a normal list item
02-21-2013 02:02 AM
Your Header should look like:
ListItemComponent {
type: "header"
Header {
title: ListItemData
touchPropagationMode: TouchPropagationMode.None
}
}i.e. just use ListItemData for the title - because from a GroupDataModel (and probably XmlDataModel) the first level of the indexpath is always returned as a string, not as an actual data item that has properties
ListItemComponent {
type: "item"
StandardListItem {
title: ListItemData.skiHill
}
},Your actual list items should have the type "item" - because this is what the GroupDataModel specifies.
You can override that by using an itemType() callback in QML, if you need it to be something different, or if you require a mixture of different types within the list
02-21-2013 02:17 AM
Thank you Peter and strobejb.
Appreciate your help