PDA

View Full Version : Loading Nested List From XML.



granjith
9 Jan 2012, 1:08 AM
Hi,

I am using Sencha Touch 1.1.
My requirement is to load NestedList from xml data. I have tried by creating a model and store as shown below

Ext.regModel('ListItem', {
fields: [{name: 'name', type: 'string'}]
});

var nestedListStore = new Ext.data.TreeStore({
model: 'ListItem',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://inblr-portal01/BallyBITest/dashboard.asmx/GetAvailableViews',
reader: {
type: 'tree',
root: 'objects',
record: 'objects'
}
}
});

The structure of the xml looks like this:

<objects>
<DashboardReports Name="Dashboard Views">
<Folder Name="Marketing" Path="/Dashboard/Marketing" isLoaded="false" isBranch="true">
<Folder Name="Charts" Path="/Dashboard/Marketing/Charts" isLoaded="false" isBranch="true">
<Report Name="15 Day Offer Margin" Path="/Dashboard/Marketing/Charts/15 Day Offer Margin" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Marketing/Charts/15 Day Offer Margin&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="Charts" isBranch="false" />
<Report Name="Daily Offer ROI By Marketing Event" Path="/Dashboard/Marketing/Charts/Daily Offer ROI By Marketing Event" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Marketing/Charts/Daily Offer ROI By Marketing Event&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="Charts" isBranch="false" />
<Report Name="Daily Offer ROI By Marketing Segment" Path="/Dashboard/Marketing/Charts/Daily Offer ROI By Marketing Segment" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Marketing/Charts/Daily Offer ROI By Marketing Segment&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="Charts" isBranch="false" />
<Report Name="Daily Offer ROI By Player Club" Path="/Dashboard/Marketing/Charts/Daily Offer ROI By Player Club" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Marketing/Charts/Daily Offer ROI By Player Club&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="Charts" isBranch="false" />
</Folder>
<Folder Name="KPIs - 3 State" Path="/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State" isLoaded="false" isBranch="true">
<Report Name="Rating Monthly Actual Win Per Location" Path="/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Monthly Actual Win Per Location" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Monthly Actual Win Per Location&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="KPIs - 3 State" isBranch="false" />
<Report Name="Rating Monthly Theoretical Win Per Location" Path="/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Monthly Theoretical Win Per Location" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Monthly Theoretical Win Per Location&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="KPIs - 3 State" isBranch="false" />
<Report Name="Rating Weekly Actual Win Per Location" Path="/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Weekly Actual Win Per Location" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Weekly Actual Win Per Location&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="KPIs - 3 State" isBranch="false" />
<Report Name="Rating Weekly Theoretical Win Per Location" Path="/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Weekly Theoretical Win Per Location" isLoaded="false" DataSource="http://inblr-portal01/ReportServer_BI?/Dashboard/Player Tracking/Comp and Point Player Tracking/KPIs - 3 State/Rating Weekly Theoretical Win Per Location&amp;rs:Command=Render&amp;rc:Toolbar=true" ViewType="KPIs - 3 State" isBranch="false" />
</Folder>
</Folder>
</DashboardReports>
</objects>

Nested List need to be loaded with "Name" attribute of each and every element in the xml.

Can anyone please help me in achieving this.

Regards
Ranjith.G

mitchellsimoens
9 Jan 2012, 7:28 AM
Using attributes on the tags aren't the best but you can use mapping to refer to them in your fields on the model.

ashapiro75
10 Jan 2012, 4:56 AM
Is there a tutorial or walkthrough somewhere on how to get XML to work with Nested Lists? I'm just learning this and getting the Json model to work too quite a bit of trial and error. I've been going through all the screen casts but there are still a lot of holes that need to be filled in. I've done quite a bit of googling all my results come to the same conclusion, there is no conclusion or solution on how to get this to work with XML.

Right now I have a simple XML document -

<?xml version="1.0" encoding="utf-8"?>
<clients>
<client>
<clientID>1</clientID>
<clientName>Hudson</clientName>
</client>
<client>
<clientID>2</clientID>
<clientName>Hudson</clientName>
</client>
<client>
<clientID>3</clientID>
<clientName>Hudson</clientName>
</client>
<client>
<clientID>4</clientID>
<clientName>Hudson</clientName>
</client>


</clients>


----- Model -----
var clientModel = new Ext.regModel('clientModel', {
fields: [{name:'clients',type:'string'},
{name:'clientID',type:'string'},
{name:'clientName',type:'string'},

]
});



--- Store & Proxy Set up ----
var clientStore = new Ext.data.XmlStore({
model: "clientModel",
proxy:{
url:"client.xml",
type:"ajax",
reader:{
type:"tree",
root:"clients",
record:"clients"
}
}
});

----- Nested List ----
var clientList = new Ext.NestedList( {
id:"clientL",
displayField:'text',
store:clientStore
});



I am getting this error - TypeError: 'undefined' is not a function (evaluating 'b.getRootNode()')


Everything I deal with is in XML, if I could get this to work with XML that would be huge for me. Everything I have found by searching says it can't be done though...


Aaron