weixin_33737774 2016-09-07 18:12 采纳率: 0%
浏览 63

Select2预载数据

Currently select2 only loads data once user starts typing. I want to preload the drop down with some default values, so once the user clicks on the drop down there are already some values to select from.. I've looked at the documentation but I couldn't find anything. Does anybody know if there is a workaround or something I could do to achieve this.

Thank you

Edit:

$('#search-paint').select2({
                placeholder: "Search By:Manufacturer, Color Name, Color Code",
                ajax: {
                    url: "/item/searchPaint",
                    dataType: "json",
                    delay: 250,
                    data: function (params) {
                        return {
                            q: params.term,
                            SprayType: $('#spray-type').val(),
                            page: params.page
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.items.data,
                            pagination: {
                                more: (data.items.current_page * data.items.per_page) < data.items.total
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) {
                    return markup;
                },
                minimumInputLength: 1,
                templateResult: formatRepo,
                templateSelection: formatRepoSelection
            });

I've tried preloading data using the data setting, but it only loads the first object and is calls the select method. I've also tried initSelection but later I discovered it has a different purpose from what I'm trying to achieve.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8