0

i am new to java script and i need some help with following code sample.

basically i want to know how can i access the values in the following array

$('#sheet').sheet({
                   title: "${title}",
                   buildSheet: true,
                   workbook: "${sheet}"
               });

this workbook : "${sheet}" contains 2d array.

actually i have forloop to print workbook : ${sheet} content

<c:forEach var="sheet" items="${workbook}">
                       <table>
                     <c:forEach var="row" items="${sheet}">
                             <tr>
                             <c:forEach var="cell" items="${row}">
                         <td>test test</td>
                       </c:forEach>
                       </tr>
                     </c:forEach>
                   </table>
           </c:forEach>  

basically i want to loop through values inside workbook variable

i really appreciate any help with that. thanks for looking into this

3
  • 1
    can you post the HTML your template outputs instead of the template? Commented Jul 14, 2012 at 3:41
  • it does not output anything, blank page.. Commented Jul 14, 2012 at 3:46
  • but when i debug jquery, i can see workbook is holding pointer to memory location Commented Jul 14, 2012 at 3:47

2 Answers 2

1

Take a look at jquery.each()

$.each(your2darray, function(key, value) {
   alert('key : ' + key + 'value:' + value);
}

http://api.jquery.com/jQuery.each/

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

Comments

0

The 2D array is actually a JavaScript object, which function similar to a dictionary or map in other programming languages. You can get the values by passing the keys into the object.

example:

myObject = { 'key' : 'value' }
//get the value 
var myValue = myObject['key'];
alert(myValue);

2 Comments

but i am confused with the way my variable is assigned, it is not like the way myObject variable is assigned. your myObject variable is assigned using equal sign but mine is different
I assumed that sheet() is a function and can access its parameters in the manner I showed. Maybe I was wrong.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.