开发者

Dynamic datagrid Httpservice

开发者 https://www.devze.com 2022-12-15 21:33 出处:网络
I receive from the httpservice with a certa开发者_如何学Pythonin frequency a string like this: 1#3#234525234

I receive from the httpservice with a certa开发者_如何学Pythonin frequency a string like this: 1#3#234525234 where row#column#value I want to display into datagrid the above string at real time; at the moment my code displays the whole string, composed by many strings like the one above. How can i solve the problem? Thanks in advance

I have the following code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns="*" creationComplete="srv.send()" >
<mx:Script>
<![CDATA[
    import mx.effects.effectClasses.AddItemActionInstance;
    import mx.effects.AddItemAction;
    import mx.collections.ArrayCollection;
    import mx.controls.dataGridClasses.DataGridColumn;
    import mx.events.*;
       import mx.rpc.events.ResultEvent;
       import mx.rpc.events.InvokeEvent;
       import mx.rpc.events.FaultEvent;
       import mx.rpc.AsyncRequest;
       import mx.rpc.AsyncResponder;
       import mx.rpc.AsyncToken;
       import mx.rpc.AbstractInvoker;
       import mx.controls.Alert;
       import mx.core.Container;
       import mx.core.IDataRenderer;
       import mx.controls.dataGridClasses.DataGridItemRenderer;
       import mx.controls.DataGrid;
       import flash.display.DisplayObject;
       [Bindable]
       public var i:Number;
       public var source:String;
       [Bindable]
       public var row:Array;
       public var column:Array;
       public var value:Array;
       public function cycle(source:String):void
       {
       var data:Array = source.split('#');
       i=0;
       for each(data in source)
       {
        row[i]=data[i]
        column[i]=data[i+1]
        value[i]=data[i+2]

        i=i+3
       }
       }

]]>
    </mx:Script>    
    <mx:HTTPService 
     id="srv" 
     url="http://10.15.20.75/server4flex/servlet/Datagen" 
     method="GET"
     /> 
    <mx:TextArea text="{cycle(srv.lastResult.toString())}" x="10" y="50" 
    width="699" height="59"/>
    <mx:AdvancedDataGrid dataProvider="{source}"  liveScrolling="true" id="dg" 
    x="10" y="117" width="621">
            <mx:columns>
                    <mx:AdvancedDataGridColumn dataField="{row[i]}"
               headerText="Riga"/>
                    <mx:AdvancedDataGridColumn dataField="{column[i]}"
               headerText="Colonna"/>
                    <mx:AdvancedDataGridColumn dataField="{value[i]}" 
               headerText="Valore"/>
            </mx:columns>
    </mx:AdvancedDataGrid>


First of all, the loop seems to be wrong, you iterate over a string source, not an array. Secondly, your grid should bind to some properties of objects stored in a dataProvider (Array, ArrayCollection, etc.). So the data provider shouldn't be a string, as in your code. Thridly, dataField is the name of the field of the object stored in the dataProvider, which value should be displayed in the grid cell.

Basicly, you need to parse your incoming string, store each row in an object and store all these objects in a collection.

So, the code should be something like:

[Bindable]
private var dataList:ArrayCollection;

public function cycle(source:String):void
{
var ac:ArrayCollection = new ArrayCollection();
for(var i:int = 0; i < data.length; i += 3) {
var dataObj:Object = {row: data[i], column: data[i+1], value: data[i+2]};
ac.addItem(dataObj);
}
dataList = ac;
}

<mx:AdvancedDataGrid dataProvider="{dataList}"  liveScrolling="true" id="dg" 
    x="10" y="117" width="621">
            <mx:columns>
                        <mx:AdvancedDataGridColumn dataField="row"
               headerText="Riga"/>
                        <mx:AdvancedDataGridColumn dataField="column"
               headerText="Colonna"/>
                        <mx:AdvancedDataGridColumn dataField="value" 
               headerText="Valore"/>
            </mx:columns>
    </mx:AdvancedDataGrid>
0

精彩评论

暂无评论...
验证码 换一张
取 消