{lang: 'de'}
Flashhilfe.de - Flash Community

Combobox mit JSON Object bestücken klappt nicht [Flex 4]

 


AntwortenRegistrieren Seite1  

babbsi#1
Benutzerbild von babbsi
Beiträge: 5
Registriert: Jul 2007

13.07.2011, 14:12

Hallo,

kann mir Jemand bei dem folgenden Code weiterhelfen, ich versuche Comboboxen mit Inhalten zu füllen. Diese Inhalte sollen aus einem JSON Objekt geliefert werden das ich mittels httpservice hole.

Bekomme nur leider keine Daten in die Combobox rein, das JSON sieht wie folgt aus:

ActionScript:
1
2
3
4
5
6
"1624":
      {
           "key": "ZYX",
           "value": "2309",
           "isPremium": "0"
        }


Meine MXML:

ActionScript:
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"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute"
            creationComplete="service.send(params)" xmlns:s="library://ns.adobe.com/flex/spark" width="250" height="250" minHeight="250" minWidth="250" backgroundColor="#e2e2e2">
   <mx:Script>
      <![CDATA[
         import com.adobe.serialization.json.JSON;
         
         import mx.collections.ArrayCollection;
         import mx.rpc.events.ResultEvent;
         
         [Bindable]
         private var myURL:String = "http://dev.ws.topdata.de/data/tdifdata.php?";
         private var params:Object = {Lookup: "DeviceManufacturerId"};
         private var dp:ArrayCollection;
         
         private function onJSONLoad(event:ResultEvent):void
         {
              //get the raw JSON data and cast to String
            var rawData:String = String(event.result);
              
              //decode the data to ActionScript using the JSON API
            //in this case, the JSON data is a serialize Array of Objects.
            var arr:Array = (JSON.decode(rawData) as Array);
              
              //create a new ArrayCollection passing the de-serialized Array
            //ArrayCollections work better as DataProviders, as they can
            //be watched for changes.
            var dp:ArrayCollection = new ArrayCollection(arr);
              
              //pass the ArrayCollection to the right Comboboxes as its dataProvider.
            sManu.dataProvider = dp;
           }
      ]]>
   </mx:Script>
   
   <mx:HTTPService id="service" method="GET" resultFormat="text" url="{myURL}" result="onJSONLoad(event)">
      
   </mx:HTTPService>
   <mx:ComboBox x="12" y="42" editable="true" width="227" cornerRadius="0" height="25" labelField="key" id="sManu"></mx:ComboBox>
   <mx:Label x="12" y="15" text="Gerätehersteller auswählen ..." width="227" fontFamily="Arial" fontSize="14" fontStyle="normal" color="#A9A9A9"/>
   <mx:Button x="173" y="211" label="Submit" cornerRadius="0" id="submit"/>
   <mx:Button x="100" y="211" label="Reset" cornerRadius="0" id="reset"/>   
   
</mx:Application>
Schlagwörter: Combobox, json
Sebastian#2
Benutzerbild von SebastianFlashhilfe.de Moderator
Beiträge: 6981
Wohnort: München
Registriert: Jan 2002

30.08.2011, 14:44