我正在设计一个数据录入应用程序,允许多个条目到其主题。例如,一个人可能已经接受了来自多个机构的教育。每个教育项目是一个表单,应用程序用户可以点击一个按钮添加另一个条目,这是一个空白但相同的形式。动态Flex表单复制
我想它涉及状态和自定义窗体组件,但不知道如何将所有东西都放在一起。有人可以阐明如何做到这一点?一些示例代码将不胜感激。
在此先感谢,
我正在设计一个数据录入应用程序,允许多个条目到其主题。例如,一个人可能已经接受了来自多个机构的教育。每个教育项目是一个表单,应用程序用户可以点击一个按钮添加另一个条目,这是一个空白但相同的形式。动态Flex表单复制
我想它涉及状态和自定义窗体组件,但不知道如何将所有东西都放在一起。有人可以阐明如何做到这一点?一些示例代码将不胜感激。
在此先感谢,
如果有要求,是否需要flex版本?或者只是使用最新的Flex 4代码?一般来说,在Flex中这是一项非常简单的任务,您可以在MXML中创建AnEntry.mxml中的类定义,它仅仅是一个TextInput(或者标签和TextInput或任何您需要的每个条目)。在Flex 3中,您在按钮的点击处理程序中调用this.addChild(new AnEntry())或在Flex 4中调用this.addElement(new AnEntry());.要提交,你需要做一个从0开始的循环,并转到this.numChildren,并将每个TextInput作为参数传递给HTTPService。下面
两个文件对编译的Flex 3.4
[AnEntry.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Label text="Link:"/>
<mx:TextInput id="theTextInput"/>
</mx:Box>
[MainApplication.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
minWidth="955"
minHeight="600">
<mx:Script>
<![CDATA[
import mx.rpc.http.HTTPService;
protected function button1_clickHandler(event:MouseEvent):void
{
var params:Object = {};
var paramCount:Number=0;
// TODO Auto-generated method stub
for(var i:Number = 0; i<numChildren; i++)
{
var currentChild:DisplayObject = getChildAt(i);
if(currentChild is AnEntry)
{
params[paramCount++] = (currentChild as AnEntry).theTextInput.text;
}
}
var httpService:HTTPService = new HTTPService();
httpService.method = "POST"
httpService.url = "http://www.shaunhusain.com/somewhere.php";
httpService.send(params);
}
]]>
</mx:Script>
<mx:Button label="Add Entry" click="this.addChild(new AnEntry())"/>
<mx:Button label="Submit Info" click="button1_clickHandler(event)"/>
</mx:Application>
请让我知道,如果这能让你在去正确的方向,如果你是Flex的一名初学者,在一周的视频中搜索Flex,他们是一个很好的教程,让你开始使用Flex开发。
修订针对Flex 4:
[MainApplication.mxml]
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.rpc.http.HTTPService;
protected function button1_clickHandler(event:MouseEvent):void
{
var params:Object = {};
var paramCount:Number=0;
// TODO Auto-generated method stub
for(var i:Number = 0; i<numChildren; i++)
{
var currentChild:DisplayObject = getChildAt(i);
if(currentChild is AnEntry)
{
params[paramCount++] = (currentChild as AnEntry).theTextInput.text;
}
}
var httpService:HTTPService = new HTTPService();
httpService.method = "POST"
httpService.url = "http://www.shaunhusain.com/somewhere.php";
httpService.send(params);
}
]]>
</fx:Script>
<mx:Button label="Add Entry" click="this.addElement(new AnEntry())"/>
<mx:Button label="Submit Info" click="button1_clickHandler(event)"/>
</s:Application>
[AnEntry.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Box xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Label text="Link:"/>
<mx:TextInput id="theTextInput"/>
</mx:Box>
我也被复杂化的东西。无论如何,你的代码明确指出了我的正确方向。我在Flex 4中运行代码时做了小的更改以反映Spark,但未按预期方式向容器添加可视元素。我错过了什么吗?再次感谢分享智慧。 – Jay 2011-02-03 18:57:39