autoComplete.js根据后台返回数据自动填充

1、引入相应js:

<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>

<script type="text/javascript" src="js/autocomplete.js" ></script>

2、前端部分:

<div class="col-xs-4">
    <label name="ModelColon" class="col-sm-4">号:</label>
    <div class="col-sm-8">
       <input type="text" id="model" name="model" οnkeyup="autoCompleteModel.start(event)" value="${(faultCodeVo.model)!''}" class="form-control"
               autocomplete="off" >
        <div class="auto_hidden" id="autoModel"></div>
        <script type="text/javascript">
            var modelData = getModel();
            function getModel(){
                var result;
                var model = $("#model").val();
                $.ajax({
                    type : "POST",
                    url : "faultCodeInfo/getModelList.do",
                    dataType : "json",
                    data : {"model":model},
                    cache : false,
                    async:false,
                    success : function(datas) {
                        result = [datas.length];
                        for(var i=0;i<datas.length;i++){
                            result[i] = datas[i].model;
                        }
                    }
                });
                return result;
            }
            var autoCompleteModel=new AutoComplete('model','autoModel',modelData);
        </script>
    </div>
</div>

3、controller层:

/*获取品牌*/
@RequestMapping("getBrandList")
@ResponseBody
public List<BrandVo> getBrandList(BrandVo brandVo) {
    logger.debug("获取品牌");
    PageResult<BrandVo> result = new PageResult<BrandVo>();
    List<BrandVo> brandVoList = faultCodeService.queryBrand(brandVo);
    return brandVoList;
}

4、service层:

List<BrandVo> queryBrand(BrandVo brandVo);

5、接口:

@Override
public List<BrandVo> queryBrand(BrandVo brandVo) {
    List<BrandVo> list = faultCodeMapper.queryBrand(brandVo);
    return list;
}

6、Mapper:

List<BrandVo> queryBrand(BrandVo brandVo);

7、查询数据库:

<select id="queryBrand" parameterType="com.gzzhongtu.forklift.core.maintain.vo.BrandVo"
        resultType="com.gzzhongtu.forklift.core.maintain.vo.BrandVo">
    SELECT id,brand FROM t_vehicle_brand
</select>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值