本帖最后由 hatesky 于 2013-1-21 14:48 编辑
import win.ui;
/*DSG{{*/
mainForm = ..win.form( bottom=86;parent=...;text="省市县三级联动";right=334 )
mainForm.add(
cmbCity={ bottom=48;right=202;left=110;vscroll=1;top=28;text="combobox";z=2;
items={ };mode="dropdown";edge=1;cls="combobox" };
cmbProvince={ bottom=48;text="combobox";left=32;vscroll=1;top=28;right=98;z=1;
items={ };mode="dropdown";edge=1;cls="combobox" };
cmbCounty={ vscroll=1;text="combobox";left=213;bottom=48;
items={ };right=305;z=3;top=28;mode="dropdown";edge=1;cls="combobox" }
)
/*}}*/
sortTab = function(stab){
var tmptab = {};
for(k,v in stab){
if(k == "n"){
continue;
}
table.insert(tmptab,k);
}
table.sort(tmptab)
return tmptab;
}
gethItem = function(stxt,stab){
var hItem;
for(k,v in stab){
if(k == "n"){
continue;
}
if(stxt == stab[k].n){
hItem = k;
break;
}
}
return hItem;
}
import web.json;
var str = string.load("\addr.txt");
var tab = web.json.parse(str);
var tmptab = sortTab(tab);
for(k,v in tmptab){
mainForm.cmbProvince.add(tab[v].n);
}
var phItem;
mainForm.cmbProvince.oncommand = function(id,event){
if(event == 0x1/*_CBN_SELCHANGE*/){
mainForm.cmbCity.clear();
mainForm.cmbCounty.clear();
phItem = gethItem(mainForm.cmbProvince.selText,tab);
tmptab = sortTab(tab[phItem]);
for(k,v in tmptab){
mainForm.cmbCity.add(tab[phItem][v].n);
}
}
}
mainForm.cmbCity.oncommand = function(id,event){
if(event == 0x1/*_CBN_SELCHANGE*/){
mainForm.cmbCounty.clear();
hItem = gethItem(mainForm.cmbCity.selText,tab[phItem]);
tmptab = sortTab(tab[phItem][hItem]);
for(k,v in tmptab){
mainForm.cmbCounty.add(tab[phItem][hItem][v].n);
}
}
}
/***
import config;
mainForm.bindConfig( config.mainForm,{
edit = "text"; //绑定edit控件的text属性值到配置文件
radiobutton = "checked";
checkbox = "checked";
combobox = "selIndex";
} );
***/
mainForm.show()
win.loopMessage();
addr.rar
(20.2 KB, 下载次数: 392)
|