<html>
<script type="text/javascript">
/** 基于 json 的级联下拉列表,支持初始化
调用 eg:
var comboselect = ComboSelectFactory(data, 'p1', 'p2', 'p3', 'p4');
设定下拉列表 value,text,parentid 名称的方法 eg:
comboselect.setProperties({id:'id',text:'text',parentid:'parentid',defaultvalue:'defaultvalue'});
初始化下拉列表集合的方法 eg:
comboselect.initSelect('gd');
*/
var ComboSelectFactory = function(data){
var comboselect = new ComboSelect(arguments);
return comboselect;
}
var ComboSelect = function(data){
this.myData = [].slice.call(data, 0, 1)[0];
this.ids = [].slice.call(data, 1);
this.setProperties({});
}
ComboSelect.prototype.setProperties = function(opt){
this.defaultvalue = opt.defaultvalue || '-';
this.id = opt.id || 'id';
this.text = opt.text || 'categoryname';
this.parent = opt.parent || 'parentid';
for(var i=0, len=this.ids.length-1; i<len; i++){
var o = this.$(this.ids[i]);
this.addEventHandler(o, 'change', this.eventHandle(o,i));
}
this.initChild(null, 0);
}
ComboSelect.prototype.eventHandle = function(o,i) {
var self = this;
var oreg=o;