The back-end data loaded by the select component of jqWEUI is items

jqweui I don't know how many people have used it. I often use it to develop webapps

Its select component is more often used, but this time I need to get the selected items data from the database instead of writing the page dead

After thinking about it for a while, I finally came up with a method, which is also effective in personal test!

Page JS:

 $.ajax({
        url: '/items/drivers/1?expressId='+[[${expressId}]],
        dataType: "json",
        success: function(data) {
            if (data) {
                var datalist = new Array();
                for (var i = 0; i < data.length; i++) {
                    var info = { "title": data[i].name, "value": data[i].id };
                    datalist.push(info);
                }
                console.log(datalist);
                $("#bind").select({
                    title: "Select driver",
                    multi: false,
                    items: datalist,
                });
            }
        }
    });
    $.ajax({
        url: '/items/drivers/0?expressId='+[[${expressId}]],
        dataType: "json",
        success: function(data) {
            if (data) {
                var datalist = new Array();
                for (var i = 0; i < data.length; i++) {
                    var info = { "title": data[i].name, "value": data[i].id };
                    datalist.push(info);
                }
                console.log(datalist);
                $("#bind1").select({
                    title: "Select escort",
                    multi: false,
                    items: datalist,
                });
            }
        }
    });

Because there are many select components to be used in the project, I took them out and wrote a controller separately

@RestController
@RequestMapping("/items")
public class LoadItemsController {

    @Autowired
    DriverService driverService;


    //Loading items of drivers of a freight company
    @RequestMapping("/drivers/{exceptType}")
    public List<Driver> driversItems(@PathVariable int exceptType,@RequestParam("expressId") int expressId) {
        List<Driver> drivers=new ArrayList<>();
        try {
            drivers = driverService.getDriverByExpressIdAndType(expressId,exceptType);
        } catch (BussException e) {
            e.printStackTrace();
        }
        return drivers;
    }

}

It's quite simple

Keywords: JSON Database

Added by EZbb on Tue, 07 Jul 2020 19:01:00 +0300