前端select之获取list获取

/**
 * 共同方法
 * 

 

/**
 * 功能描述: 下拉框值变化 使用例子:
 * 
 * <pre>
 * onSelectOptionsChange({
 *   id : &quot;userDefineType&quot;, // 下拉框id:必需
 *   url : &quot;${ctx}/help/save&quot;,// url:必需
 *   itemValue : &quot;value&quot;, // 返回值的value值字段名,必需
 *   itemLabel : &quot;label&quot;, // 返回值的label值字段名,必需
 * // param: {},           // 参数:非必需
 * // emptyOption: true,   // 是否包含空选项,默认false
 * // beforeAppendOption: function(data) {
 * //   return data;
 * // },// 后台返回数据时特殊处理
 * // afterSuccess: function() {},// 处理结束后回调,非必需
 * // async: false,         // 是否异步,默认true
 * });
 * </pre>
 */
function onSelectOptionsChange(options) {
  if (!options.url) {
    alertError("缺少参数: url");
    return;
  }
  if (!options.id) {
    alertError("缺少参数: id");
    return;
  }
  if (!options.itemValue) {
    alertError("缺少参数: itemValue");
    return;
  }
  if (!options.itemLabel) {
    alertError("缺少参数: itemLabel");
    return;
  }
  options.async = options.async == false ? options.async : true;
  httpRequest({
    url: options.url,
    data: options.param,
    async: options.async,
    success: function (data) {
      if (options.beforeAppendOption) {
        var returnData = options.beforeAppendOption(data);
        if (returnData) {
          data = returnData;
        }
      }
      var id = "#" + options.id;
      var oriVal = $(id).val();
      var val = null;
      $(id + " option").remove();
      if (options.emptyOption == true) {
        $(id).append("<option value=''></option>");
      }
      for (item of data) {
        if (oriVal == item[options.itemValue]) {
          val = item[options.itemValue];
        }
        $(id).append("<option value='" + item[options.itemValue] + "'>" + item[options.itemLabel] + "</option>");
      }
      if (val != null) {
        $(id).val(val);
      }
      if (options.afterSuccess) {
        options.afterSuccess(data);
      }
      return true;
    },
  });
}

例子:

 $("#userDefineType").val("");
    onSelectOptionsChange({
      id: "userDefineType",   // 下拉框id:必需
      url: "${ctx}/wave/waveType/query",// url:必需
      itemValue: "typeCode",     // 返回值的value值字段名,必需
      itemLabel: "typeName",     // 返回值的label值字段名,必需
      param: {whCd: data[0].whCd},    // 参数:非必需
      emptyOption: true,      // 是否包含空选项,默认false
    // afterSuccess: function(){},// 处理结束后回调,非必需
      async: false,         // 是否异步,默认true
    });
<select id="userDefineType" name="userDefineType" class="input-small" style="height:20px; margin-bottom: 8px;"><select>
  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值