Bonjour à tous, j'ai un petit souci pour référencer un dataProvider dans un ItemRenderer sachant que ce dernier est utilisé par un DataGrid et que les deux dataProvider utilisent la même source XML.
Voici un peu de code pour plus de compréhension.
product.xml
Le module d'accueil mxml :
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 <?xml version="1.0" encoding="utf-8"?> <catalog> <product id="1"> <nom>Papillon</nom> <url>http://blabla.jpg</url> <description>description du produit</description> <prix>0</prix> <tailles> <taille> <label>Small</label> <data>S</data> </taille> <taille> <label>Medium</label> <data>M</data> </taille> </tailles> </product> </catalog>
ProductItemRenderer.mxml :
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 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()"> <mx:Style source="default.css" /> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] private var catalog:ArrayCollection; private function init():void { catalog= new ArrayCollection(catalogModel.product); } ]]> </mx:Script> <mx:Model id="catalogModel" source="product.xml" /> <mx:DataGrid left="10" top="10" right="10" bottom="10" dataProvider="{catalog}" variableRowHeight="true"> <mx:columns> <mx:DataGridColumn headerText="Produit" itemRenderer="ProductItemRenderer" /> </mx:columns> </mx:DataGrid> </mx:Application>
Résultat attendu : Liste des tailles dans la comboBox.
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 <?xml version="1.0" encoding="utf-8"?> <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="586" height="216" title="{data.nom}"> <mx:CurrencyFormatter id="cf" currencySymbol="€" precision="2" /> <mx:Image left="10" top="10" bottom="10" source="{data.url}" scaleContent="true" autoLoad="true" width="135"/> <mx:Label x="153" y="10" text="{data.description}" width="403" height="54"/> <mx:Label x="153" y="72" text="Prix :"/> <mx:Label x="196" y="72" text="{cf.format(data.prix)}" id="prix"/> <mx:ComboBox x="196" y="98" selectedIndex="0" editable="false" dataProvider="{data.taille}" labelField="label" enabled="true" > </mx:ComboBox> </mx:Panel>
Résultat obtenu : Liste vide, pas d'erreurs...
Une petite idée ?
Merci à tous
Partager