12-30-2012 06:51 AM
Hello everyone,
So my problem is that I have no idea how to get a value when an attribute exists. I will try to be more detailed below.
I have a XML document with the following sctructure:
<listOfStations> <station> <StationIcon>0332.jpg</StationIcon> <StationName>JD Inside</StationName> <StationURL>http://www.jdinside.com/</StationURL> <StationStreamURL type="pls"> http://www.panel-streaming.com/tunein.php/jdinside/playlist.pls </StationStreamURL> <StationButton/> <StationButtonSelected/> </station> </listOfStations>
I am receiving correct data from it and pass it ListView as a model. There is no mistake in this part of code. Here is a QVariant:
QVariant(QVariantMap, QMap(("StationButton", QVariant(QString, "") ) ( "StationButtonSelected" , QVariant(QString, "") ) ( "StationIcon" , QVariant(QString, "0332.jpg") ) ( "StationName" , QVariant(QString, "JD Inside") ) ( "StationStreamURL" , QVariant(QVariantMap, QMap((".data", QVariant(QString, "http://www.panel-streaming.com/tunein.php/jdinside /playlist.pls") ) ( "type" , QVariant(QString, "pls") ) ) ) ) ( "StationURL" , QVariant(QString, "http://www.jdinside.com/") ) ) ) I can get Station name in QML to set is as title for cell - ListItemData.StationName
Can get StationUrl - ListItemData.StationURL
Can get type of Station Stream Url (which is attribute) - ListItemData.StationStreamURL.type
BUT, I have no idea how to get Url (which is value). ListItemData.StationStreamURL.data doesn't work and returns
TypeError: Result of expression 'chosenItem.StationStreamURL' [undefined] is not an object.
You would ask me what choseItem is. It is
var chosenItem = dataModel.data(indexPath);
I use it in onTrigerred to get an element which has been pressed.
12-31-2012 01:45 AM
i think the element 'StationStreamURL' doesnt always exist?
try wrapping into defensive code:
if(ListItemData.StationStreamURL){
ListItemData.StationStreamURL[".data"]
}
BUT, I have no idea how to get Url (which is value). ListItemData.StationStreamURL.data doesn't work and returns
your above code doesn't work, the key is NOT "data" but ".data". So you should use the javascript array accessor notation to retrieve that value (see my example above).