PDA

View Full Version : Repeater and XML data...


fx.barrett
10-03-2008, 04:07 PM
I'll be short:

1) I'm loading some XML dynamically and I'm using it as my repeater's dataProvider
2) I want to create a few text fields in my repeater and populate each field with the content of a specific child
3) I want to be able to read all the text fields content with 1 button click

Here's a fake XML example on how I have my stuff organized:

<?xml version="1.0" encoding="utf-8"?>
<content>
<news show="true">
<title>New Title 1</title>
<date>10.05.2008</date>
<description>News Description ONE.</description>
</news>
<news show="true">
<title>New Title 2</title>
<date>11.06.2008</date>
<description>News Description TWO.</description>
</news>
<news show="false">
<title>New Title 3</title>
<date>12.07.2008</date>
<description>News Description THREE.</description>
</news>
</content>
I'm trying to populate the 3 text fields in my repeater each time with the correct "title" , "date" and "description" but I'm having some troubles... Especially when trying to read all the data from each text field...

I'm doing something like this:

<mx:Repeater id="rep_comp" dataProvider="{_xml}" width="100%" height="100%">
<mx:Panel width="100%" height="100%" verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundAlpha="0"
borderStyle="none" cornerRadius="0">
<mx:TextInput width="100%" height="20" id="news_title" text="{rep_comp.currentItem.title}"/>
<mx:TextInput width="100%" height="20" id="news_date" text="{rep_comp.currentItem.date}"/>
<mx:TextInput width="100%" height="100%" id="news_description" text="{rep_comp.currentItem.description}"/>
</mx:Panel>
</mx:Repeater>
But if I run it in debug mode then I'm getting these errors:

warning: unable to bind to property 'title' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'description' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'date' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'title' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'description' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'date' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'title' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'description' on class 'XML' (class is not an IEventDispatcher)
warning: unable to bind to property 'date' on class 'XML' (class is not an IEventDispatcher)
And I don't know how to get around this...

Finally, the problem when reading a text field's data... how can I read a certain text fields text input ( situated in the repeater ) by clicking on a button that is not inside the repeater but outside of it ???

Any help is really appreciated... I tried surfing for stuff on the net but I can't seem to find anything that could help me out with this...

fx.barrett
10-05-2008, 09:27 PM
Duh, no one ? :( Darn, I was really hoping that someone has already encoutered this problem and solved it or at least found a workaround...

drkstr
10-05-2008, 10:48 PM
http://livedocs.adobe.com/flex/3/html/repeater_3.html

Check out the section on referencing repeated components.

As far as your binding warnings go, it doesn't really matter unless you want to update your data and have your text inputs reflect the changes. This usually isn't needed if the user is changing the values directly in the text inputs themselves. If you do need to do this, convert your XML into an ArrayCollection of strongly typed Objects that extend EventDispatcher and are [Bindable].


Best Regards,
~Aaron

semperfried76
12-31-2008, 06:22 PM
You should try using a list instead of a repeater- this has the added advantage of rendering only the items that are needed onscreen at the time rather than every item returned by your dataprovider.

Anyways, in response to your last question, I ran into a similar problem a while ago- in your button's click function, you need to specify that the variable you want to draw data from is within the selected item of your repeater (I suggested using a list for this reason, I don't even know if you can do this with a repeater, but with a list it works pretty well):

repeaterName.selectedItem['variableName']

(note, 'variableName' will not be the name of whatever is displaying the text in the item itself such as a text field or label, but rather the name of the data item your displayed text is coming from - the XML element.)

I have tested this method with my own implementation of wordpress in flex when trying to pull post item numbers from items that only displayed post titles (yet still drew all the data from the post element)- so you don't even need to be displaying all of the data you want to use for this method to work.

Oddly enough, this is done EXACTLY the same way in WPF, which is where I got the idea to try it this way in the first place.