Dans le fichier .as tu ne dois pas mettre de balise.
exemple du fichiers .as
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 34 35 36
|
import mx.collections.ArrayCollection;
// ArrayCollection dynamique
[Bindable]
public var information:ArrayCollection = new ArrayCollection([{ARTICLE:0 ,QUANTITé:0 }]);
// Initialise le DataGrid ayant pour id : tab
private function initDataGrid():void{
tab.dataProvider = information;
}
private function addLine():void{
// Récupération des entrées du formulaire
var addArticle:String = article.text;
var addQtité:String = qtité.text;
// Création d'un nouvel élément
var newItem:Object = new Object();
newItem.ARTICLE= addArticle;
newItem.QUANTITé = addQtité;
// Ajoute un élément
information.addItem(newItem);
//Exemple pour supprimer un élément en fonction de son index (dans une boucle for par exemple)
//information.removeItemAt(i);
}
private function removeLine():void{
var remove:int =parseInt(lig.text);
information.removeItemAt(remove);
} |
Ton .mxml ressemblerais à ça (attention, je suis en Flex 4)
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 34 35 36 37 38 39 40 41 42 43 44
|
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script source="leJoliScript.as"/>
<mx:Panel x="22" y="10" width="1200" height="823" label="Profil de l'unité" borderColor="#E2E2E2"
borderStyle="outset" layout="absolute">
<mx:Accordion left="10" top="24" width="936" height="754">
<mx:Canvas width="1000" height="426" label="Saisie des besoins">
<mx:Panel width="543">
<mx:title><![CDATA[ Formulation Des Besoins D'une Unité]]></mx:title>
<mx:DataGrid id="tab" dataProvider="{information}"/>
<mx:Form>
<mx:HBox width="250">
<mx:Label width="80" text="ARTICLE : "/>
<mx:TextInput id="article" width="160"/>
</mx:HBox>
<mx:HBox width="250">
<mx:Label width="80" text="QUANTITé : "/>
<mx:TextInput id="qtité" width="160"/>
</mx:HBox>
<mx:HBox width="250">
<mx:Label width="80" text="UF:"/>
<mx:TextInput width="160"/>
</mx:HBox>
<mx:Button label="Ajouter" click="addLine()"/>
<mx:HBox width="250">
<mx:Button label="Suprimer" click="removeLine()"/>
<mx:TextInput id="lig" width="160"/>
</mx:HBox>
</mx:Form>
<!-- tableau contenant les données du ArrayCollection -->
<!-- Formulaire d'ajout -->
<mx:Button label="Envoyer"/>
</mx:Panel>
</mx:Canvas>
</mx:Accordion>
</mx:Panel>
</s:Application> |
Voilà
Si tu veux utiliser le binding, tu peux aussi lié ton tableau automatiquemennt à tes champs texte.
Tu peux écrire tes TextInput comme ceci :
<mx:TextInput id="article" width="160" text="{tab.selectedItem.ARTICLE}"/>
Partager