0

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

1 Answer 1

2
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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.