博客
关于我
下拉框查询遇见的问题
阅读量:705 次
发布时间:2019-03-17

本文共 1714 字,大约阅读时间需要 5 分钟。

在项目中,我们需要实现房类下拉框与散客价下拉框的动态绑定。通过前端调用后端API,我们能够在房类下拉框选中具体房型后,实时获取并加载相应的散客价数据。以下是实现方法和过程的详细说明。

首先,在前端,我们设置房类下拉框的改变事件,通过获取选中房型ID来调用后端接口获取对应的散客价数据。具体实现如下:

// 初始化房类下拉框createSelect("Abbreviation", "jianceng");// 房类下拉框数据改变时,触发散客价下拉框数据绑定$("#Abbreviation").change(function () {    var roomtypeID = $("#Abbreviation").val();    // 绑定散客价下拉框数据    createSelect("PFITPrice", "SelectPt?RoomTypeID=" + roomtypeID);    // 清空现有选项    $("#PFITPrice").empty();});

在后端,我们创建一个控制器来处理房型ID到散客价数据的映射关系。具体实现如下:

public ActionResult SelectPt(int RoomTypeID){    // 获取房型ID对应的房价ID    var priceID = (from tbRoomType in myModels.SYS_RoomType                 where tbRoomType.RoomTypeID == RoomTypeID                 select tbRoomType.PriceID).Single();        // 获取客户价数据    var customerPriceList = (from tbHotelRates in myModels.SYS_HotelRates                           where tbHotelRates.PriceID == priceID                           select new                            {                                id = tbHotelRates.PriceID,                                text = tbHotelRates.FITPrice                           }).ToList();    // 将数据格式转换为 JSON 格式    var jsonList = Common.Tools.SetSelectJson(customerPriceList);        return Json(jsonList, JsonRequestBehavior.AllowGet);}

在数据回填的场景中,我们需要将加载的房价数据动态地设置到表单中。主要步骤包括:

$.post("SelectGBT", { RoomID: RoomID }, function (data) {    // 同时加载房型信息    loadDatatoForm("formfangjianxiugai", data);        // 回填房类下拉框    createSelect("RAbbreviation", "jianceng", data.RoomTypeID);        // 回填散客价信息    createSelect("RFITPrice", "SelectPt?RoomTypeID=" + data.RoomTypeID, data.PriceID);});

需要注意的是,在处理房价数据时,我们采用了动态获取方式,避免了静态数据的直接引用。这种动态绑定方式能够保证数据的实时更新,满足用户对最新数据查询需求的要求。通过前后端的协同工作,我们实现了房型与散客价的灵活映射,提升了系统的交互体验和灵活性。

转载地址:http://kmwez.baihongyu.com/

你可能感兴趣的文章
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>