我完成如下
我有一个方法带来特定表的数据,因为我的参数给定了该方法,
现在我想从相应的表中获取数据,它也列表,并发送回动态和形式动态Grid&动态添加dataprovider,就像它在flex侧的对应表colomns一样?
远程对象(java类)
public List<List<String>> getMasterTableData(String name)
{
String designMaster = "tbl_design_master"+name;
String masterTableName = "tbl_master"+name;
String[][] res ;
List<List<String>> list = new ArrayList<List<String>>();
try
{
st = connection.createStatement();
ResultSet rs1 = st.executeQuery("select * from "+designMaster);
int len = 0;
while(rs1.next())
{ len++; }
ResultSet rs2 = st.executeQuery("select * from "+masterTableName);
while(rs2.next())
{
List<String> ll = new ArrayList<String>();
for(int i=1;i<=len; i++)
{
ll.add(rs2.getString(i));
}
list.add(ll);
}
}
catch (SQLException e) {
e.printStackTrace();
}
return list;
}
flex代码:
<mx:RemoteObject id="RO" destination="adminServiceImpl">
<mx:method name="getMasterDesign" result="getMasterDesignRH(event)" fault="FH(event)" />
<mx:method name="getMasterTableData" result="getMasterTableDataRH(event)" fault="FH(event)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
[Bindable] private var ac:ArrayCollection = new ArrayCollection();
public function init(Str:String):void
{
RO.getMasterDesign(Str);
Application.application.selectedgridItem = Str;
RO.getMasterTableData(Str);
}
private function getMasterDesignRH(event:ResultEvent):void
{
Application.application.designList = event .result as ArrayCollection;
var aColumns:Array = new Array();
for(var i:int=0; i< Application.application.designList.length; i++)
{
var dgc:DataGridColumn = new DataGridColumn();
dgc.headerText = Application.application.designList.getItemAt(i).colName;
//dgc.dataField = Application.application.designList.getItemAt(i).colName;
aColumns.push(dgc);
}
mainGrid.columns = aColumns;
}
private function getMasterTableDataRH(event:ResultEvent):void
{
ac = event.result as ArrayCollection;
mainGrid.dataProvider = ac;
}
private function FH(event:FaultEvent):void{
Alert.show(event.fault.faultString);
}
]]>
</mx:Script>
<mx:HBox width="100%" height="80%">
<mx:DataGrid id="mainGrid" width="100%" height="100%" />
</mx:HBox>
getMasterDesign是一个ArrayCollection,它填充了要显示的列名和组件
Ex:getMasterDesign(emp) empMasterDesign表如下所示
colName component
--------------------
EmpName textBox
empSal textBox
empDesi ComboBox
empMasterData:
empName | EmpSal | EmpDesi
abc 1000 Cler## Heading ##ck
xyz 2000 Manager
现在我希望通过使用它的设计和放大,动态地创建一个Datagrid。动作脚本中的主数据表我完成了每一个,我的dataGrid已经形成了他的主设计,但数据没有显示?
答案 0 :(得分:1)
您必须将dataField
设置为适当的值。根据给定的数据,它看起来像元数据中的colName
字段,并且表中的相应名称不相同。例如,设计中为EmpName
,原始表中为empName
;没有字段匹配 - empSal
vs EmpSal
,empDesi
vs EmpDesi
。修复此问题,将colName分配给dataField,你应该好好去。