How can I make php array into Javascript object code?.
-
possible duplicate of Dynamically Add to Javascript ObjectFelix Kling– Felix Kling2012-09-20 04:48:09 +00:00Commented Sep 20, 2012 at 4:48
-
I recommend to read developer.mozilla.org/en-US/docs/JavaScript/Guide/…Felix Kling– Felix Kling2012-09-20 04:48:27 +00:00Commented Sep 20, 2012 at 4:48
Add a comment
|
1 Answer
You can try this. This is how you dynamically name object properties and object values. I am assuming you want to build this dynamically where the property names are coming from a source. All you have to do is loop through the values
var treeData = {};
Loop Here
var nameProperty = "propertyName";
var nameValue = "propertyValue";
var childProperty = "child";
var childValue = {};
Try This.
1 Comment
user1684586
Thanks. This helped a lot. But I am still having a problem with the loop. How do I keep the hierarchical structure as shown in the original question. Do I increment 1++ every iteration. I am a bit confused? Can You Help? I would appreciate it:)