1:利用json(json格式的配置文件)和jquery 实现根据配置的页面展示
$.get("js/ymcfg.json", function (data) {
parseinit(JSON.parse(data));
},"json");
var parseinit = function (jsonObj) {
//可以将json对象进行遍历展现到页面
}
js的一些小东东综合:
(1):js中数组的定义:var arr = [];
(2):js中对象的定义:var goodArrmap = new Object();//Object类型在js中是个天然的map 用起来很方便
(3):js中json对象的定义:var json = {};
(4):js中将json对象转换为json字符串:JSON.stringify(json);
(5) js数组中移除某一个元素可以使用下面的function:
Array.prototype.baoremove = function(dx)
{
if(isNaN(dx)||dx>this.length){return false;}
this.splice(dx,1);
}
如 arr.baoremove(2);
附:ymcfg.json 的配置文件为:
[
{
"id" : "searchType",
"value" : "文档类型",
"ifMultiSel" : "false",
"Operator" : "in",
"DataType" : "string",
"typeItems" : [{
"id" : "searchTypeNoLimit",
"value" : "不限",
"able" : "#resType,#proType"
}, {
"id" : "resReport",
"value" : "word",
"able" : "#resType;#proType",
"disable" : "#resType(null);#proType(null)"
}, {
"id" : "appTool",
"value" : "excle",
"able" : "#resType(#resTypeNoLimit,#online_rpt);#proType(#proTypeNoLimit,#colligateBusi,#net)",
"disable" : "#resType(#kpi_normal,#analysis,#cub,#cst,#report,#res_default,#sql,#view,#res_link,#pms_price,#pms_active,#tbl,#repository);#protype(#terminal,#famlymarket,#datamarket)"
}
]
},
{
"id" : "resType",
"value" : "子类型",
"ifMultiSel" : "true",
"Operator" : "in",
"DataType" : "string",
"typeItems" : [{
"id" : "resTypeNoLimit",
"value" : "不限",
"able" : "#proType"
}, {
"id" : "kpi_normal",
"value" : "PPT",
"able" : "#proType",
"disable" : "#proType(null)"
}
]
},
]
附件中是一个实现页面动态配置的小例子。