数据字典工具类

var dicObj=[];
//获取所有字典项
$.ajax({
           type:"post",
           url:ctx + "/dict/getAllDictList?time"+new Date().getTime(),
           dataType:"json",
           data:{
               
           },
           async:false,
           beforeSend:function(){
               
           },
           success:function(res){
               dicObj=res;
           }
});

//根据类型查询
function getDicByTypeCode(typeCode){
    var result=[];
    for (var i = 0; i < dicObj.length; i++) {
        if (dicObj[i].typeCode == typeCode) {
            result.push(dicObj[i]);
        }
    }
    return result;
}

//根据查询类型&&查询编码
function getDicByCode(typeCode,dictCode){
    var result="";
    for (var i = 0; i < dicObj.length; i++) {
        if (dicObj[i].typeCode == typeCode&&dicObj[i].dictCode == dictCode) {
            result= dicObj[i].dictName;
        }
    }
    return result;
}

 

使用:
var dic_exchange_method=getDicByTypeCode('EXCHANGE_METHOD');
    //交换方式
    $('#exchangeMethod').combobox({
        data:dic_exchange_method,
        valueField:'dictCode',
        textField:'dictName'
    });
    
    alert(getDicByCode('EXCHANGE_METHOD','2'));

 

posted @ 2017-07-10 14:43  伍叶春  阅读(741)  评论(0编辑  收藏  举报