I want to create a js array of type
Name(
{title : "Mr.",firstname : "Bill",lastname : "Gates"},
{title : "Mr.",firstname : "Bill",lastname : "Gates"},
{title : "Mr.",firstname : "Bill",lastname : "Gates"}
)
So basically i want to create associated array. All the examples are like converting javascript array to java but in my case i want the other way round. I will be filling this array from java.
JSArray and JsMixedArray seems to be doing this but i could figure out how to add to them.
One approach could be to use a JSNI method to create the items/entries of your Array/Map as follows:
JsArray arr = JavaScriptObject.createArray().cast();
arr.push(newEntry("Mr.", "Bill", "Gates"));
....
private final native JavaScriptObject newEntry(String title,
String firstname, String lastname)/*-{
return {title: title, firstname: firstname, lastname: lastname};
}-*/;
You could also try to create the data structure you have in mind using the JSON utility methods: Put JSONObjects inside a JSONArray.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With