jquery - Not able to fetch values from two dimensional array in Javascript -
i inserting values in 2 dimensional array according role_id i.e
var tdarray = [[]]; tdarray[40].push(22); where 40 role_id , 22 value. when print value shows null
alert(tdarray[40][0]); //this shows no value. i guess 2 dimensional array in jquery not allow insert values @ specific position.can suggest me can overcome this. entire code here
var tdarray = [[]]; var incr = 1; var check; $(function () { $('.toggle_checkbox').change(function () { if (check === null) {} else { if (this.name == check) { incr++; } else { incr = 1; } } var tval = $(this).val(); check = this.name; tdarray[this.name].push(tval); }); }); html code
<table border = "0" cellspacing = "0" cellpadding = "1" > <tbody> <c:foreach items="${accessrightvalues}" var="rights" > <tr style="height: 40px;"> <td style="width: 240px;"><input type="checkbox" name="<c:out value="${rights.roleid}"/>" value="1" class="toggle_checkbox"> add </td> <td style="width: 240px;"><input type="checkbox" name="<c:out value="${rights.roleid}"/>" value="2" class="toggle_checkbox">update</td> <td style="width: 240px;"><input type="checkbox" name="<c:out value="${rights.roleid}"/>" value="3" class="toggle_checkbox">view </td> <td style="width: 240px;"><input type="checkbox" name="<c:out value="${rights.roleid}"/>" value="4" class="toggle_checkbox">delete </td> <td style="width: 240px;"><input type="checkbox" name="<c:out value="${rights.roleid}"/>" value="5" class="toggle_checkbox">assign </td> </tr> </c:foreach> </tbody> < /table> my problem id 40 can hold more 1 value .so want know how can using multidimensional array in jquery.also there can more 1 role_id's such 50,57 again hold more 1 value.please me regarding same. want pass 2 dimensional array in spring controller. tdarray[40][0] =1; tdarray[40][1] =3; tdarray[40][2] =5; tdarray[48][0] =2; tdarray[48][1] =3;
where 40,48 role_id of user , 1,3,5 access_rights want store in database.
in order use push() function in key 40 have initialize position array well.
var tdarray = []; tdarray[40] = []; tdarray[40].push(22) // works alert(tdarray[40][0]); in code provided:
var tdarray = []; ... // check if it's array before initialize if(!tdarray[this.name] instanceof array) { tdarray[this.name] = []; // or tdarray[this.name] = new array(); } tdarray[this.name].push(tval);
Comments
Post a Comment