开发者

Populating an array collection by parsing a string

In ActionScript I have string as

str="subject,r1,r2:a,b:1,2:3,4";

dynamically i have split this string and build array collection开发者_开发问答 as given below

arraycoll.addItem({subject:a ,r1:1,r2:3});

this example of one set

the arraycollection should be built dynamic i have tried but not successful


var str:String ="subject,r1,r2:a,b:1,2:3,4";
var parts:Array = str.split(":");
var props:Array = parts[0].split(",");
var count:Number = parts[1].split(",").length;
var items:Array = [];
var values:Array = [];
var i:Number, j:Number;
for(i = 0; i < props.length; i++)
  values.push(parts[i + 1].split(",")); 
for(i = 0; i < count; i++)
{
  items.push({});
  for(var j = 0; j < props.length; j++)
  {
    items[i][props[j]] = values[j][i];
  }
}
var arCol:ArrayCollection = new ArrayCollection(items);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜