如何在flex中动态地将dataProvider分配给DataGrid?

发布于 2024-09-10 13:52:48 字数 2979 浏览 3 评论 0原文

我做了如下

我有一个方法,可以带来特定表的数据,正如给定该方法的参数一样,

现在我想从相应的表及其列表中获取数据,并动态地发回 Flex 和表单 Grid & 。动态添加 dataprovider 到 Flex 端对应的表列?

远程对象(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

现在我希望通过使用其设计和功能动态地在 Flex 中创建一个 Datagrid。动作脚本中的主数据表我完成了所有工作,我的数据网格已经形成了他的主设计,但数据没有显示?

i done as follows

i have a method with brings data of particular table, as given my parameter to that method,

now i want to fetch data from corresponding table and it too list, and send back flex and form dynamically Grid & add dataprovider dynamically as for its corresponded table colomns in flex side ?

Remote objec(java class)

 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 code :

<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 is an ArrayCollection, which is filled with the column names and components to be displayed

Ex : getMasterDesign(emp)
empMasterDesign table looks like as follows

colName    component 
--------------------
EmpName    textBox
empSal     textBox 
empDesi    ComboBox 

empMasterData:

empName | EmpSal | EmpDesi 
abc       1000     Cler## Heading ##ck 
xyz       2000     Manager

Now i want this create a Datagrid in flex dynamically by using its design & master data table in action script i done everyting , my dataGrid had formed as for his master design,but data is not showing ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉 2024-09-17 13:52:48

您必须将dataField 设置为适当的值。从给定的数据来看,元数据中的colName字段与其在表中对应的名称不一样。例如设计中为EmpName,原表中为empName;没有任何字段匹配 - empSalEmpSalempDesiEmpDesi。解决这个问题,将 colName 分配给 dataField,然后就可以开始了。

You must set the dataField to the appropriate value. From the given data, it looks like colName field in the metadata and its corresponding name in the table are not the same. For example it is EmpName in the design and empName in the original table; none of the fields match - empSal vs EmpSal, empDesi vs EmpDesi. Fix that, assign colName to the dataField, and you should be good to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文