简体   繁体   中英

Flex Spark datagrid

i have an error adding dataprovider on my spark datagrid:

Multiple initializers for property 'dataProvider'. (note: 'dataProvider' is the default property of 'spark.components.DataGrid').

My data is from s:httpService declaration and i put it in data grid something like this

<s:DataGrid includeIn="formState" x="348" y="57" width="287" dataProvider="{myHttpService}">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="data1" headerText="Data Field 1"></s:GridColumn>
            <s:GridColumn dataField="data2" headerText="Data Field 2"></s:GridColumn>
            <s:GridColumn dataField="data3" headerText="Data Field 3"></s:GridColumn>
        </s:ArrayList>
    </s:columns>
    <s:typicalItem>
        <fx:Object dataField1="Sample Data" dataField2="Sample Data" dataField3="Sample Data"></fx:Object>
    </s:typicalItem>
    <s:ArrayList>
        <fx:Object data1="data1" data2="data1" data3="data1"></fx:Object>
        <fx:Object data1="data2" data2="data2" data3="data2"></fx:Object>
        <fx:Object data1="data3" data2="data3" data3="data3"></fx:Object>
        <fx:Object data1="data4" data2="data4" data3="data4"></fx:Object>
    </s:ArrayList>
</s:DataGrid>

and my http service is:

<s:HTTPService id="myHttpService" url="http://host.com/mydata.php"/>

Your code specifies the dataProvider twice, inadvertently I think.

The first time it is specified as a property on the tag, on this line.

<s:DataGrid includeIn="formState" x="348" y="57" width="287" dataProvider="{myHttpService}">

The second time it is specified as a child of the DataGrid, with these blocks:

<s:ArrayList>
    <fx:Object data1="data1" data2="data1" data3="data1"></fx:Object>
    <fx:Object data1="data2" data2="data2" data3="data2"></fx:Object>
    <fx:Object data1="data3" data2="data3" data3="data3"></fx:Object>
    <fx:Object data1="data4" data2="data4" data3="data4"></fx:Object>
</s:ArrayList>

You can't specify the dataProvider in both cases.

Additionally, I'll add that your code, as is, is using myHttpService as the dataProvider (in thef irst line). You probably want to use the results of the myHttpService call as the dataProvider; not the actual myHttpService object.

I believe you could bind to myHttpService.lastResults if you wanted, by my preference is to have a formal results handler that deals with handling the results, Conceptually like this:

<s:HTTPService id="myHttpService" url="http://host.com/mydata.php" result="onMyResult(event)"/>

protected function onMyResult(event:ResultEvent):void{
  this.myDataGrid.dataProvider = new ArrayCollection(event.results as Array);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM