Reputation: 3407
I get a List from Java to javascript in AJAX response.
So i have to iterate the List of Beans and display each Bean as a record in the table.
Eg;
[[prop1=value1,prop2=value2],[prop3=value3,prop4=value4],[prop5=value5,prop6=value6]]
After iterating list it must display as follows.
value1 value2
value3 value4
value5 value6
It is having complexity in iterating the list in javascript.
I don't know how to iterate in javascript..
Any idea or response is highly Appreciated :-)
Upvotes: 0
Views: 7107
Reputation: 8401
Make sure the data are in proper JSON format.
When you can convert it to javascript object. If you are using JQuery you can do,
jQuery.parseJSON( jsonString );
Then you can loop it like a normat Javacript array.
for (var i = 0; i < myStringArray.length; i++) {
alert(myStringArray[i]);
//Do something
}
Upvotes: 3
Reputation: 13994
It is a string, so you will have to loop over it using string functions. I recommend using a regular expression, with which you can extract values based on certain patterns.
See http://www.regular-expressions.info/ for an introduction and more information.
Upvotes: 0