Reputation: 75127
How can I define an array of arrays and pass that variable into a function so I can manipulate it at JavaScript?
As like:
JSP side:
object.method({ {"#id1",2}, {"#id2",3}...});
...
JS side:
var object= {
defaults: {
idSelector: "#id1"
},
method: function(options) {
if (options && !jQuery.isEmptyObject(options))
$.extend(this.defaults, options);
var that = this;
var opts = that.defaults;
//Try to reach every array step by step?
});
}
}
Upvotes: 0
Views: 402
Reputation: 75127
The functions' variable that will get the values should be like that(JSON format will be used):
defaults: [{
idSelector: '',
faqId: ''
}]
Upvotes: 0
Reputation: 10580
Here's one of the ways to do that:
Your javascript client code can fetch this json dictionary, something like:
$.getJSON('ajax/test.json', function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
});
now items
points to a bunch of <li>
with your results
Upvotes: 0
Reputation: 43235
use json data format . Convert your object into json string in your JSP page. Parse that JSON string in your javascript.
Upvotes: 1