尝试修改 asmselect 以获得很长的选择列表

发布于 2024-10-18 20:43:50 字数 587 浏览 3 评论 0原文

我的页面上有一个使用 asmselect 的多重选择,效果非常好。

我正在尝试向页面添加另一个多选,但遇到问题。大约有 11,000 个选项导致 asmselect 永远无法加载,因为它循环遍历 asmselect jquery 代码中的整个列表。即使我可以缩短加载时间,用户浏览整个列表以找到他们的选项也不会太容易。

我的想法是添加按钮,该按钮会弹出一个对话框(我成功地使用页面上其他地方的对话框来添加选择列表的选项),用户可以在其中输入一些过滤器信息,然后可以从过滤列表中进行选择。因此,他们输入 101,它会列出选项“10100”、“22101”、“31015”等。他们选择“10100”。选择后主屏幕上将显示“10100”。然后,他们可以再次点击按钮并输入“105”,这将为他们提供一个新的过滤选择列表,然后他们选择“10500”,该列表现在与“10100”一起显示在主屏幕上。

第一个问题,有没有更好的方法来处理这个问题?

其次,我可以使用 asmselect 的格式来显示新选择的项目,以便它与其他 asmselect 的格式匹配,并使用带有“删除”的内置功能来取消选择项目。我正在查看asmselect代码,但是我的jquery知识非常有限,我无法弄清楚。有人能指出我正确的方向吗?

I have a multiselect on my page using asmselect which works wonderfully.

I am trying to add another multiselect to the page, but encountering problems. There are about 11,000 options which causes the asmselect take forever to load since it's looping through the whole list in the asmselect jquery code. Even if I could improve the load time, it wouldn't be too easy for the user to look through the entire list to find their option.

My thoughts were to add button which would pop-up a dialog (I'm successfully using dialogs elsewhere on the page for adding options to select lists), where the user can enter some filter info and then can select from a filtered list. So, they type 101 and it lists options "10100", "22101", "31015" etc. They select "10100". "10100" displays on the main screen as selected. They can then hit the button again and enter "105" which will give them a new filtered select list and they select "10500" which now shows along with "10100" on the main screen.

First question, is there a better way to handle this?

Second, can I use the formatting for asmselect to display my newly selected items so that it matches with the formatting of my other asmselect and use the built-in functionality with the "remove" for unselecting an item. I'm looking at the asmselect code, but my jquery knowledge is very limited and I can't figure it out. Could someone point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我心暖 2024-10-25 20:43:50

我通过使用 droplistFilter 插件 在对话框中提供选项下拉列表来实现此目的。当从下拉列表中选择一个选项并单击对话框的“添加”按钮时,该选项被添加到我的多重选择中(使用 asmselect 插件)并设置为选定状态,并且我从下拉列表中禁用了该选项。在我的 $(document).ready(function() { 中,我将多选中的每个选定选项设置为在下拉列表中禁用。

        $('#Vendor_IDs').asmSelect({
            sortable: false
        });
        $('#vendor').droplistFilter();
        $('#Vendor_IDs option:selected', this).each(function () {
            $("#vendor option[value='" + $(this).val() + "']").attr("disabled", true);
        });

        $('#popupAddVendor').dialog(
        {
            autoOpen: false,
            modal: true,
            width: 600,
            buttons:
            {
                'Add': function () {
                    var v = $('#vendor').val();
                    if (v.length > 1) {
                        $('#Vendor_IDs').append($('<option></option>').val(v).html($('#vendor option:selected').text()).attr("selected", true));
                        $('#Vendor_IDs').change();
                        $('#vendor option:selected').attr("disabled", true).attr("selected", false);
                        $('#vendor').attr('selectedIndex', 0);
                    }
                    $(this).dialog('close');

                },
                'Cancel': function () {
                    $(this).dialog('close');
                }
            }
        });

I achieved this by having a dropdown list of the options in a dialog using a droplistFilter plugin. When an option was selected from the dropdown and the "add" button of the dialog was clicked, the option was added to my multiselect (using the asmselect plugin) and set to selected and I disabled the option from the dropdown list. In my $(document).ready(function() { I set each selected option in my multiselect to disabled in the dropdown.

        $('#Vendor_IDs').asmSelect({
            sortable: false
        });
        $('#vendor').droplistFilter();
        $('#Vendor_IDs option:selected', this).each(function () {
            $("#vendor option[value='" + $(this).val() + "']").attr("disabled", true);
        });

        $('#popupAddVendor').dialog(
        {
            autoOpen: false,
            modal: true,
            width: 600,
            buttons:
            {
                'Add': function () {
                    var v = $('#vendor').val();
                    if (v.length > 1) {
                        $('#Vendor_IDs').append($('<option></option>').val(v).html($('#vendor option:selected').text()).attr("selected", true));
                        $('#Vendor_IDs').change();
                        $('#vendor option:selected').attr("disabled", true).attr("selected", false);
                        $('#vendor').attr('selectedIndex', 0);
                    }
                    $(this).dialog('close');

                },
                'Cancel': function () {
                    $(this).dialog('close');
                }
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文