0
我希望有人可以帮助我.....ArrayCollection通过匹配项目循环
我想建立一个问卷模块的动态表单。建立一些以前的帖子我使用的过程类似于有问题的“How to generate a form(<mx:form>) dynamically in flex?”我已经设法证明了扩展XML以包括日历,组合框等事实。
我的问题是,现在需要获取来自ArrayCollection的数据而不是来自xml文件。我期待循环通过交流和类型=“文本”呈现textinput字段,其中类型=“日历”呈现日历等等
我的代码到目前为止只是看着一个textinput字段(和对不起所有的评论包括)是: -
[Bindable]
public var AC:ArrayCollection = new ArrayCollection([
{type:'text', direction:'horizontal', tooltip:'test tooltip', label:'my textbox label', id:'1'},
{type:'text', direction:'horizontal', tooltip:'another tooltip', label:'another label', id:'2'}
]);
private function init():void
{
var form:Form = new Form();
for each(var elements:String in AC)
{
switch([email protected]())
{
case "text":
var fi:FormItem = new FormItem();
// fi.toolTip = elements.tooltip.toString();
// fi.required = getglobalprofile.required.toString();
// fi.direction = getglobalprofileb[i][email protected];
var li:Label = new Label();
// li.text = getglobalprofileb[i][email protected];
// li.width = 100;
var ti:TextInput = new TextInput();
ti.text = "test";
ti.width = 200;
form.addChild(fi);
fi.addChild(li);
fi.addChild(ti);
// break;
}
}
this.addChild(form);
}
]]>
</mx:Script>
<!-- Data grid added just to check that AC getting data-->
<mx:DataGrid id="profile" selectedIndex="1" dataProvider="{AC}" width="100%" height="50%" />
<mx:Form id="form" name="form">
</mx:Form>
,如果您有兴趣使用XML版本(只用于呈现)让我知道,我将在此以及
我不太明白你的问题。 foreach循环有问题吗?什么具体不工作? – 2010-06-09 03:54:58
是的,它是每个循环。我期待在AC中找到列'type'=“text”并执行一些操作,然后查看列'type'=“calendar”并执行一些不同的操作等。 – charlie 2010-06-09 07:54:25