Iterate Java List in Java Script?

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

Answers


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
}

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.


Need Your Help

Restkit seed core-data with objects from a local file on launch

iphone ios core-data restkit restkit-0.20

I'm working on an app, in which I need to seed core-data with some local data stored in a file and I'm using Restkit.

Php list of forms

php javascript html forms

I have the following piece of code, inside a php script

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.