日志文章

2007年09月10日 11:03:09

flex-包装form



后台数据组织:

StBillTypeVO bill = new StBillTypeVO();
ArrayCollection acbilltype = new ArrayCollection();
    try {
        HashMap hsmap = (HashMap) PropertyUtils.describe(bill);
        Iterator it = hsmap.keySet().iterator();
        while (it.hasNext()) {
          String key = (String) it.next();
          Object val = PropertyUtils.getProperty(bill, key);
          if (val instanceof Class) {
            continue;
          }
          if (null == val) {
            continue;
          }else{
            ASObject asob = new ASObject ();
            asob.put("key", key);
            asob.put("value", val);
            acbilltype.add(asob);
          }
        }
    }
前台:
var arr:Array;
arr=mainpanel.getChildren();//mainpanel为<mx:Panel
submit.getform(ArrayCollection(result),arr);
子函数:

public static function getform(result:ArrayCollection,ay:Array):void//回传
{
  for(var j:int=0;j<result.length;j++)
  {
  for(var k:int=0;k<ay.length;k++)
  {
  if(ay[k] is Label && ay[k].id==result[j].key)
  {
    ay[k].text=result[j].value;
    break;
  }
  if(ay[k] is TextInput && ay[k].id==result[j].key)
  {
    ay[k].text=result[j].value;
    break;
  }
  if(ay[k] is Text && ay[k].id==result[j].key)
  {
    ay[k].text=result[j].value;
    break;
  }
  if((ay[k] is TextArea) && ay[k].id==result[j].key)
  {
    ay[k].text=result[j].value;
    break;
  }
  else if(ay[k] is RichTextEditor&& ay[k].id==result[j].key)
  {
    ay[k].htmlText=result[j].value;
    break;
  }
  //else if(ay[k] is RadioButton && ay[k].groupName==result[j].key && ay[k].id==result[j].value)
  else if(ay[k] is RadioButton && ay[k].groupName==result[j].key && ay[k].value==result[j].value)
  {
    ay[k].selected=true;
    break;
  }
  else if(ay[k] is CheckBox && ay[k].id==result[j].key)
  {
    if(result[j].value!=null && result[j].value=="0"){
    //ay[k].name=result[j].value;
    ay[k].selected=false;
    break;
    }else{
    //ay[k].name=result[j].value;
    ay[k].selected=true;
    break;
    }
  }
  else if(ay[k] is ComboBox && ay[k].id==result[j].key)
  {
    ay[k].selectedIndex=result[j].value;
    break;
  }
  else if(ay[k] is DateField && ay[k].id==result[j].key)
  {
    ay[k].text=result[j].value;
    break;
  }
  else if(ay[k] is Form||ay[k] is Canvas||ay[k] is TabNavigator||ay[k] is Panel||ay[k] is Box||ay[k] is VBox||ay[k] is HBox||ay[k] is TitleWindow||ay[k] is ControlBar||ay[k] is ApplicationControlBar||ay[k] is DividedBox||ay[k] is HDividedBox||ay[k] is VDividedBox||ay[k] is FormHeading||ay[k] is FormItem||ay[k] is Grid||ay[k] is Tile)
  {
    var con:Container=Container(ay[k]);
    var ar:Array=con.getChildren();
    var res:ArrayCollection=new ArrayCollection();
    res.addItem(result[j]);
    submit.getform(res,ar);
  }
  }
  }
}




Tags: flex  

类别: flex/AJAX |  评论(0) |  浏览(974) |  收藏
发表评论
看不清楚,换一张