miniUI中 ComboBox联动的问题的优化

前两天写的miniUI中 ComboBox联动的问题中虽然解决了需求问题,但是,所属部门的部门是写死在txt中的,不是很好,应该动态获取,还有所属地市是直接从数据库去查询的,这个和所属部门一样有可以优化的地方,都可以从字典表里去读取出来,那样的话部分的提高了程序的扩展性,代码如下:

html中代码:

<table style="width: 100%; height: 30px;">
                    <tr>
                        <td align="left" style="width: 50px;">
                            <div id="cbFirst" style="float: left;width: 120px;">
                                <input id="cmbFirst" value="Selected" url="../data/SearchText.txt" class="mini-combobox" allowinput="false" onvaluechanged="GetFollow()";/></div>&nbsp;&nbsp;
                            <div id="cbTextbox" style="float: left;margin-left:10px;width: 110px;">
                                <input id="key" class="mini-textbox" onenter="onKeyEnter" />
                            </div>
                            <div id="cbOrganization" style="float: left;margin-left:10px;width: 110px;display:none">
//这里有所改动其中原来指向txt的部门和所属地市在这里不指定,在JS中去根据选择的查询条件来动态加载; <input idField="Key" textField="Value" id="keyOrganization" class="mini-combobox" allowinput="false" /> </div> <div id="cbDepartment" style="float: left;margin-left:10px;width: 110px;display:none"> <input idField="Key" textField="Value" id="keyDepartment" class="mini-combobox" allowinput="false" /> </div> &nbsp; <a class="mini-button" iconcls="icon-search" onclick="searchData()" plain="true"> 查询</a> </td> </tr> </table>

JS中代码:

//根据选的筛选条件不一样,改变第二个div的格式
function GetFollow() {
    var selectInfo = mini.get("cmbFirst").getValue();
    if (selectInfo == "UserName" || selectInfo == "RealName" || selectInfo == "Mobile") {
    //当选择的是可以输入的时候显示一个,隐藏另一个
        document.getElementById("cbTextbox").style.display = "block";
        document.getElementById("cbOrganization").style.display = "none";
        document.getElementById("cbDepartment").style.display = "none";
    }else if (selectInfo == "Organization") {
        document.getElementById("cbTextbox").style.display = "none";
        document.getElementById("cbOrganization").style.display = "block";
        document.getElementById("cbDepartment").style.display = "none";
        //选择所属地市的时候加载地市数据,这里动态加载所属地市的数据
        mini.get("keyOrganization").setUrl("http://www.cnblogs.com/../dictionary.ashx?dic=city");
    } else if (selectInfo == "Department") {
        document.getElementById("cbTextbox").style.display = "none";
        document.getElementById("cbOrganization").style.display = "none";
        document.getElementById("cbDepartment").style.display = "block";
        //选择所属部门的时候加载部门数据,这里动态加载所属部门的数据
        mini.get("keyDepartment").setUrl("http://www.cnblogs.com/../dictionary.ashx?dic=department&type=1");
    }
}

//#region //查询
function searchData() {
    var selectInfo = mini.get("cmbFirst").getValue();
    var key;
    if (selectInfo == "Selected") {
        alert("请您选择查询条件");
    } else if (selectInfo == "UserName" || selectInfo == "RealName" || selectInfo == "Mobile") {
        key = mini.get("key").getValue();
    } else if (selectInfo == "Organization") {
        key = mini.get("keyOrganization").getText();
    } else if (selectInfo == "Department") {
        key = mini.get("keyDepartment").getText();
        //截取部门前两位,数据库需要据此来查询数据
        key = key.substring(0, 2);
    }
    var newkey = { key: key, selectInfo: selectInfo };
    grid.load(newkey);
}
function onKeyEnter(e) {
    searchData();
}
//#endregion
posted @ 2012-10-30 17:07  peace-lee  阅读(1386)  评论(2)    收藏  举报