0

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 :-)

1
  • 1
    This would be 1,000x easier if you could get your Java code to emit JSON. As I don't know Java, the best I can do is point you to Google. Commented Sep 21, 2012 at 9:06

2 Answers 2

3

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

Comments

0

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.

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.