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