Bonjour,
Comme beaucoup je me lance dans la programmation FLEX.
J'utilise le plugg in eclipse et je souhaite remplir un datagrid avec un fichier XML externe. Apres avoir parcouru qques articles sur le web j'ai bien réussi a affiché dans un FormItem la valeur d'un attribut de mon fichier mais je ne parvient pas remplir mon DataGrid de manière statique et eventuellement de maniere dynamique.
Je post mon code (qui est assez simple).
Merci de votre aide.
Le code mxml :
Le contenu de mon fichier xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 <?xml version="1.0"?> <!-- DataGrid control example. --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:XML id="fichierXML" source="MyXML.xml"/> <mx:Panel title="DataBase Employee" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10"> <mx:Label width="100%" color="blue" text="Select a row in the DataGrid control."/> <mx:DataGrid id="dg" width="100%" height="100%" rowCount="1" dataProvider="{fichierXML}"> <mx:columns> <mx:DataGridColumn dataField="{fichierXML.personne[0].adresse.nom}" headerText="Name"/> <mx:DataGridColumn dataField="{fichierXML.personne[0].adresse.prenom}" headerText="Phone"/> <mx:DataGridColumn dataField="{fichierXML.personne[0].adresse.nom}" headerText="Email"/> </mx:columns> </mx:DataGrid> <mx:Form width="100%" height="100%"> <mx:FormItem label="Name"> <mx:Label text="{fichierXML.personne[1].adresse.nom}"/> </mx:FormItem> <mx:FormItem label="Prenom"> <mx:Label text="{fichierXML.personne[1].adresse.prenom}"/> </mx:FormItem> <mx:FormItem label="Street"> <mx:Label text="{fichierXML.personne[1].adresse.@numero}-{fichierXML.personne[1].adresse.@rue}"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <?xml version="1.0" encoding="UTF-8"?> <root> <personne> <adresse rue="rue de la liberation" numero="36" > <nom>Franck</nom> <prenom>Michael</prenom> </adresse> </personne> <personne> <adresse rue="boulevard hoch" numero="13" > <nom>Arthur</nom> <prenom>Rambo</prenom> </adresse> </personne> <personne> <adresse rue="avenue leclerc" numero="45" > <nom>Nina</nom> <prenom>Simone</prenom> </adresse> </personne> </root>
Partager