JS中多位数组的处理
/////添加 2012 10 10 定义一个易做图数组
var array_2;
function Array_2(nRow, nColumn) {
var array1 = new Array();
for (i = 0; i < nRow; i++) {
array1[i] = new Array();
for (n = 0; n < nColumn; n++) {
array1[i][n] = '';
}
}
return array1;
}
//数组中去重复的值
var uniq = function(arr) {
var a = [], o = {}, i, v, len = arr.length;
if (len < 2) {
return arr;
}
for (i = 0; i < len; i++) {
v = arr[i];
if (o[v] !== 1) {
a.push(v);
o[v] = 1;
}
}
return a;
}
function iniData() {
var elems = $("ul.expanded");
var arr = new Array();
for (var i = 0; i < elems.length; i++) {
arr[i] = elems[i].id;
}
var x = uniq(arr);
array_2 = Array_2(10, 2); 定义一个10行2列的数组
for (var j=0;j<x.length;j++) {
for (var jj = 0; jj < elems.length; jj++) {
if (x[j] == elems[jj].id) {
array_2[j][0] = elems[jj].id;
array_2[j][1] += elems[jj].innerHTML;
}
}
}
RangeHtml(x);
}
function RangeHtml(arrx) {
var elems = $("div#powerlist");
for (var i = 0; i < elems.length; i++) {
if (i < arrx.length) {
var title = array_2[i][0];
var content = array_2[i][1];
var rangeContent = "<ul id=\"nav\"> <li><a href='javascript:void(0)' onclick=\"DoMenu('powermenu" + i + "')\">" + title + "</a> <ul id='powermenu" + i + "' class=\"expanded\">" + content + "</ul></li></ul>";
elems[i].innerHTML = rangeContent;
}
else {
elems[i].style.Display = "none";
}
}
}
当时写这段js是用于在1期项目中权限管理没有层级结构的效果,合并相同类型的权限菜单,用户层级结构显示、
补充:web前端 , JavaScript ,