0

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?
      });
   }
}

3 Answers 3

1

use json data format . Convert your object into json string in your JSP page. Parse that JSON string in your javascript.

Sign up to request clarification or add additional context in comments.

Comments

0

Here's one of the ways to do that:

  1. Your servlet can return a text, representing a json dictionary. Here's the documentation of a JSON API http://www.json.org/java/
  2. 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

1 Comment

I will just pass parameters from javascript(at document.ready()) to my .js file.
0

The functions' variable that will get the values should be like that(JSON format will be used):

defaults: [{
  idSelector: '',
  faqId: '' 
}]

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.