下拉框combobox

本文档介绍了如何使用EasyUI创建下拉框,并从后台获取数据加载到Combobox中。通过示例展示了如何从控制器返回JSON数据填充下拉框,以及如何获取Combobox的选中文本值和处理onchange、onselect事件。

【1】后台传查询出数据,返回list.tojson

[1]

<th>&nbsp;&nbsp;开始时间(年):</th>
                    <td>
                        <input id="startTime" name="startTime" class="easyui-combobox" data-options="valueField:'id',textField:'text',panelHeight:'auto'" style=" width:140px;">
                    </td>

[2]

$.post('@Url.Action("GetYearList")', {}, function(data) {
            $("#startTime").combobox('loadData', data);
            $("#endTime").combobox('loadData', data);
            $("#btn_search").click();
        }, 'json');

[3]

        public string GetYearList()
        {
            EfHelper_RemoteSenseModel efHelper = new EfHelper_RemoteSenseModel();
            List<decimal?> years = efHelper.FindAll<T_BUS_GDP>().OrderBy(r => r.YEAR).Select(r => r.YEAR).Distinct().ToList();//V_BUS_GDP
            List<YearBox> yearBox = new List<YearBox>();
            years.Sort();
            for (int i = 0; i < years.Count; i++)
            {
                YearBox year = new YearBox();
                year.id = years[i].ToString();
                year.text = years[i].ToString();
                year.selected = (i == 0 ? true : false);
                yearBox.Add(year);
            }

            return yearBox.ToJson();
        }

        public struct YearBox
        {
            public bool selected;
            public string text;
            public string id;
        }

【2】后台直接返回json字符串

[1]

<th>&nbsp;&nbsp;数据类型:</th>
                    <td>
                        <input id="DataStyle" name="DataStyle" class="easyui-combobox" data-options="valueField:'id',textField:'text',panelHeight:'auto'" style=" width:140px;">
                    </td>

[2]

        $.post('@Url.Action("GetStyle")', {}, function (data) {
            $("#DataStyle").combobox('loadData', data);
            
            $("#btn_search").click();
        }, 'json');

[3]

        /// <summary>
        /// 数据类型下拉框
        /// </summary>
        /// <returns></returns>
        public string GetStyle()
        {
            return "[{\"id\":\"0\",\"text\":\"GDP\",\"selected\":true},{\"id\":\"1\",\"text\":\"第三产业产值\"},{\"id\":\"2\",\"text\":\"工业总产值\"},{\"id\":\"3\",\"text\":\"固定资产投资总额\"},{\"id\":\"4\",\"text\":\"出口总额\"},{\"id\":\"5\",\"text\":\"人均GDP\"}," +
             "{\"id\":\"6\",\"text\":\"实际利用外商直接投资\"},{\"id\":\"7\",\"text\":\"外商投资占GDP比例\"},{\"id\":\"8\",\"text\":\"人均GDP增长率\"},{\"id\":\"9\",\"text\":\"全社会固定资产投资增长率\"},{\"id\":\"10\",\"text\":\"工业产值增长率\"},{\"id\":\"11\",\"text\":\"第三产业产值增长率\"},{\"id\":\"12\",\"text\":\"第三产业从业人员\"}]";
        }

【3】获取下拉框的文本值

$("#DataStyle").combobox("getText")

下拉框改变onchange事件,onselect事件

        $("#DataStyle").combobox({

            onChange: function (n, o) {
                //alert($("#DataStyle").combobox("getText"));//改变前的值
            },
            onSelect: function () {
                //$("#DataStyle").combobox("getText")
                //$("#th1").text() = "";
                //$("#th1").text() = ("#DataStyle").combobox("getText");
                get1($("#DataStyle").combobox("getText"));
                //alert($("#th0").text());//选中的值
        }
        });

【4】改变th的文本内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值