jquery ligerui下拉框赋值问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012716909/article/details/52038000


//初始化事件下拉列表
function initEventManager(){
    eventManager = $("#tree1").ligerTree({
        checkbox:false,
        single :true,
        nodeWidth:200,
        textFieldName:'id',
        url:"monitorDefinedManager.do?method=getAllMonitorDefined",
        onSelect: function (node){
            treeSelectNodeID=node.data.id;
            selectData = node.data;
            showMonitorDataAll();
        } ,
        onAfterAppend: function(parentNode, newdata){
            if(treeSelectNodeID==null||treeSelectNodeID=="null"||treeSelectNodeID==undefined){
                var firstBaby = eventManager.getData()[0];
                treeSelectNodeID=firstBaby.id;
            }
            eventManager.selectNode(treeSelectNodeID);
        },
        onError: function () { 
            window.location = basePath+"base/reLogin.jsp";
        },
        onError: function () { 
            window.location = basePath+"base/reLogin.jsp";
        }
    });
}

/**
 * 方法说明:显示所有监视器信息
 */
function showMonitorDataAll(){
    cacheDeviceDisplay={};
    cacheStyleDisplay={};
   <span style="color:#ff0000;"> var i='';</span>
    var tablehtmlarr = [];
    for (var oneMonitorStyleIndex in selectData.monitorStyleList){
        var oneMonitorStyle = selectData.monitorStyleList[oneMonitorStyleIndex];
        if(oneMonitorStyle.doAnalyze==true){
            cacheStyleDisplay[oneMonitorStyle.monitorStyleName]=false;
            cacheDeviceDisplay[oneMonitorStyle.monitorStyleFlag]=oneMonitorStyle.monitorStyleFlag;
            <span style="color:#ff0000;">i+=oneMonitorStyle.monitorStyleFlag;</span>
        }
    }
    setComboxData(comboxStyle,cacheStyleDisplay,i);
}

//事件下拉框
function initCombox(){
<span style="color:#3333ff;">    comboxStyle=$("#eventtype").ligerComboBox({ 
        isShowCheckBox: true, 
        isMultiSelect: true,
        valueFieldID: 'comboxEventValue',
        onSelected:function(value, text){
            var zeroValue=$("#eventtype").val();
            if( zeroValue ==""){  //下拉框如果为空,则给赋值   
                $("#eventtype").val("全部");
            }
        }
    }); </span>
}

function setComboxData(combox,cacheData,i){
    var checkTmp=new Array();
    var data=new Array();
<span style="color:#ff0000;">    var id=i;
    var i=0;
    var j=2;</span>
    for(var name in cacheData){ 
        var cell={
            "text":name,
            <span style="color:#ff0000;">"id":id.substring(i,j)</span>
        };
       <span style="color:#33ffff;"> </span><span style="color:#3333ff;">data.push(cell);</span>
        cacheData[name]&&(checkTmp.push(name));  
<span style="color:#ff0000;">        i=i+2;
        j=j+2;</span>
    }
    $(combox.valueField).val(checkTmp.join(";"))
    combox.setData(data);//setData会自动触发select事件,所以只需提前设置选择值即可
}
在js中用cacheStyleDisplay={};存入几个数(cacheDeviceDisplay[oneMonitorStyle.monitorStyleFlag]=oneMonitorStyle.monitorStyleFlag;)本想会一一对应存入,结果存入的数自动进行从大到小排序,解决办法 :var i='';  i+=oneMonitorStyle.monitorStyleFlag;将其数字直接一个个拼凑起来,在取得时候通过id.substring(i,j)一个个取出。在对下拉框text、id赋值的时候一一对应赋值。


阅读更多
换一批

没有更多推荐了,返回首页