将textarea文本作为对象发送到datagrid

时间:2011-06-16 23:10:39

标签: actionscript-3 flex4 flash-builder

我想要一个包含多个字符串的文本区域,将其值发送到数组,并将数组转换为对象。然后,对象填充数据网格。我无法确定从哪里开始:

var arrayString:String = myTextArea.text;
var newArray:Array = arrayString.split(",");
var n:int=newArray.length;
while (n--)
{
    newArray[n]=Number(newArray[n])
    var obj:Object = new Object();
    obj.label = newArray[n];
    this.myDataGrid.addItem(obj );
}

1 个答案:

答案 0 :(得分:2)

var arrayString:String = myTextArea.text;
var newArray:Array = arrayString.split(",");
var n:int=newArray.length;

var dataProvider:ArrayCollection = new ArrayCollection;

while (n--)
{
    newArray[n]=Number(newArray[n])
    var obj:Object = { label: newArray[n] };
    dataProvider.addItem(obj);
}

this.myDataGrid.dataProvider = dataProvider;