简体   繁体   English

3个组合框,一个一个地更改,每个自动选择第一项

[英]3 combobox box,change one by one,each select the first item auto

I have 3 comboboxes,when i select the first combobox,i want the first item of the second combobox and third combobox been selected auto. 我有3个组合框,当我选择第一个组合框时,我想自动选择第二个组合框和第三个组合框的第一项。 when the first item of second combobox been selected,will trigger the onselect event of the third combobox,but the parameter record is undefined 当选择第二个组合框的第一项时,将触发第三个组合框的onselect事件,但参数record未定义

$("#c2").combobox({
            onSelect:function(record)

when i select an item of the first combobox ,the record here is undefined. 当我选择第一个组合框的一个项目时,此处的record是不确定的。 when i select an item of the second combobox,it is not 当我选择第二个组合框的项目时,它不是

why? 为什么?

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
    <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
    //simulate the database
    var data={};
    data.id1=[{value:"id1",text:"aa1"},{value:"id2",text:"aa2"}];
    data.id2=[{value:"id3",text:"aa3"},{value:"id4",text:"aa4"}];
    data.id1.id1=[{value:"id1",text:"aaa1"},{value:"id2",text:"aaa2"}];
    data.id1.id2=[{value:"id3",text:"aaa3"},{value:"id4",text:"aaa4"}];
    data.id2.id1=[{value:"id5",text:"aaa5"},{value:"id6",text:"aaa6"}];
    data.id2.id2=[{value:"id7",text:"aaa7"},{value:"id8",text:"aaa8"}];
    $(function(){
        var c1id;
        $("#c1").combobox("loadData",[{value:"id1",text:"a1"},{value:"id2",text:"a2"}]);
        //change c2 box when c1 on select
        $("#c1").combobox({
            onSelect:function(record){
                c1id=record.value;
                $("#c2").combobox("clear");
                $("#c2").combobox("loadData",data[record.value]);
                try{var c2data=$("#c2").combobox("getData");//c2data.length is 0?
                value=c2data[0].text;
                $("#c2").combobox("select",value);}
                catch(e){

                }
            }
        }) 
        $("#c2").combobox({
            onSelect:function(record){
                $("#c3").combobox("clear");
                $("#c3").combobox("loadData",data[c1id][record.value]);
                try{var c2data=$("#c3").combobox("getData");//c2data.length is 0?
                value=c2data[0].text;
                $("#c3").combobox("select",value);}
                catch(e){

                }
            }
        })
    });
</script>
</head>
<body>
<input id="c1" class="easyui-combobox">
<input id="c2" class="easyui-combobox">
<input id="c3" class="easyui-combobox">
</body>
</html>

When setting the value of a combobox, you should pass a value , not a text , by which I mean 设置组合框的值时,您应该传递一个 ,而不是一个text ,我的意思是

value=c2data[0].text;
$("#c2").combobox("select",value);}

should be 应该

value=c2data[0].value;
$("#c2").combobox("select",value);}

If you select an nonexistent value, the combobox does displays it, but not associate it with an object. 如果选择一个不存在的值,则组合框会显示它,但不会将其与对象关联。 That is why you get a undefined . 这就是为什么您得到undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM