下拉框combobox用法&级联餐单

若是下来内容不用后台取数据,直接写死的话不用url属性,直接用data便可:数据库

 <input id="orderstate" name="orderstate" class="easyui-combobox" />
$(function(){
$("#orderstate").combobox({
                valueField: 'id',
                textField: 'text',
                width: 80,
                autoShowPanel: true,
                data: [{ id: -1, text: '支付结果' }, { id: 1, text: '成功' }, { id: 0, text: '失败' }],
                onLoadSuccess: function () {
                    var val = $(this).combobox('getData');
                    if (val != null && val.length > 0) {
                        $(this).combobox('select', val[0]["id"]);//val[0].id也能够
                    }

                }
            });
});

 

一、单个下拉框:json

  <td> <input id="waytype" name="waytype"   class="easyui-combobox" /></td>
 $(function () {
              var _actiontype = $('#waytype').combobox({
                  type: "GET",
                  dataType: 'json',
                  url: "/xxxx/xxxx.json",
                  editable: false,
                  valueField: 'id',
                  textField: 'text',
                  onSelect: function (record) {
                  },
                  onLoadSuccess: function (data) {
                      if (data.length == 0) {
                          $.messager.alert("系统提示", "数据库异常,请联系管理员!", "warning");
                      } else {
                          var data1 = $('#waytype').combobox('getData');  //赋默认值
                          if (data1.length > 0) {
                              $("#waytype").combobox('select', data1[0].actionid);
                          }
                      }
                  }

              });
});

二、级联餐单:ui

 <td> <input id="actiontype" name="actiontype"   class="easyui-combobox" style="width:80px" /></td>
 <td> <input id="waytype" name="waytype"   class="easyui-combobox" /></td>
 $(function () {
              var _actiontype = $('#actiontype').combobox({
                  type: "GET",
                  dataType: 'json',
                  url: "/xxx/xxx.json",
                  editable: false,
                  valueField: 'actionid',
                  textField: 'actionname',
                  onSelect: function (record) {
//如下是根据第一个餐单选择值不一样而去获取不一样的二级连餐单,若是只是简单的根据第一个餐单值而去获取对应的数据源,不须要判断直接获取就ok了
if (record.actionid == "get") { _waytype.combobox({ disabled: false, url: '/xxx/GetWayTypeJson1', valueField: 'id', textField: 'text' }).combobox('clear'); } else { _waytype.combobox({ disabled: false, url: '/xxx/GetWayTypeJson2', valueField: 'id', textField: 'text' }).combobox('clear'); } }, onLoadSuccess: function (data) { if (data.length == 0) { $.messager.alert("系统提示", "数据库异常,请联系管理员!", "warning"); } else { var data1 = $('#actiontype').combobox('getData'); //赋默认值 if (data1.length > 0) { $("#actiontype").combobox('select', data1[0].actionid); } } } }); var _waytype = $('#waytype').combobox({ editable: false, disabled: false, valueField: 'id', textField: 'text', onLoadSuccess: function (data) { if (data.length == 0) { $.messager.alert("系统提示", "数据库异常,请联系管理员!", "warning"); } else { var data1 = $('#waytype').combobox('getData'); //赋默认值 if (data1.length > 0) { $("#waytype").combobox('select', data1[0].id); } } } }); });