flex - Populating an array collection by parsing a string -
in actionscript have string
str="subject,r1,r2:a,b:1,2:3,4";
dynamically have split string , build array collection given below
arraycoll.additem({subject:a ,r1:1,r2:3});
this example of 1 set
the arraycollection should built dynamic have tried 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; < props.length; i++) values.push(parts[i + 1].split(",")); for(i = 0; < 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);
Comments
Post a Comment