日期:2014-05-16  浏览次数:20563 次

页面json展示
$(function () {

$.get("cfg.json", function (data) {
init(JSON.parse(data));
},"json");

var init = function (g_list) {
var arr = [];
arr[arr.length] = "<ul>";
for (var i = 0; i < g_list.length; i++) {
arr[arr.length] = "<ul><li id='" + g_list[i]["id"] + "'>" + g_list[i]["value"] + "";
var typeItems = g_list[i]["typeItems"];
for (var k = 0; k < typeItems.length; k++) {
arr[arr.length] = "<a href='#' ";
for (var key in typeItems[k]) {
arr[arr.length] = key + "='" + typeItems[k][key] + "' "
}
arr[arr.length] = " >" + typeItems[k]["value"] + "</a>";
}
arr[arr.length] = "</li><br>";
}
arr[arr.length] = "</ul>";
$("#tDiv").html(arr.join(""));
var selDiv = $("#tDiv");

var ableFun = function (ableStr) {
var ableArr = ableStr.split(";");
for (var i = 0; i < ableArr.length; i++) {
if (ableArr[i].indexOf("(") < 0) {
//selDiv.find(ableArr[i]).show().find("a").show();
selDiv.find(ableArr[i]).removeClass("tmp").find("a").removeClass("tmp");
} else {
var trStr = ableArr[i].substring(0, ableArr[i].indexOf("("));
//selDiv.find(trStr).show();
selDiv.find(trStr).removeClass("tmp");
var aStr = ableArr[i].substring(ableArr[i].indexOf("(") + 1, ableArr[i].indexOf(")"));
//selDiv.find(aStr).show();
selDiv.find(aStr).removeClass("tmp");
}

}
}

var disableFun = function (disableStr) {
var disableArr = disableStr.split(";");
for (var i = 0; i < disableArr.length; i++) {
if (disableArr[i].indexOf("(") < 0) {
//selDiv.find(disableArr[i]).hide().find("a").hide();
selDiv.find(disableArr[i]).addClass("tmp").find("a").addClass("tmp");
} else {
var aStr = disableArr[i].substring(disableArr[i].indexOf("(") + 1, disableArr[i].indexOf(")"));
//selDiv.find(aStr).hide();
selDiv.find(aStr).addClass("tmp");
}

}
}

$("#tDiv a").click(function () {
var ableStr = $(this).attr("able");
//alert(ableStr + "\n" + (!ableStr));
if (ableStr) {
ableFun(ableStr);
}

var disable = $(this).attr("disable");
//alert(disable +"\n" + (!disable));
if (disable) {
disableFun(disable);
}
var set = $(this).attr("set");
//alert(set +"\n" + (!set));
if (set) {}

});
}

});