jQueryUI 默认多选并具有套索切换选定状态

发布于 2024-10-16 08:59:06 字数 698 浏览 2 评论 0原文

我正在尝试实现一个类似比较图表的表格,除了我需要的一些功能更改之外,大量可选对象可以完美地工作。我发现这两个问题都在前面的问题中得到了解决,但都没有提供完整的解决方案。

这个问题解决了多重选择行为默认,但只说“我自己做的”而不提供任何内容。看看 selectable 的内部结构,我发现如果我使用 !event.metaKey 条件,我可能会得到我正在寻找的行为而不会遇到太多麻烦,但想知道是否有人有一个不涉及编辑的解决方案内部结构。

同样,此页面解决了我想要的套索切换效果,但我不确定在代码中,套索功能已更改,并且据报告脚本的其余部分(可排序功能)在 chrome 或 IE8 中不起作用(link)并且已经过时了,我不想依赖整个事情。

因此,如果有人能帮助我解决这两个问题,我将不胜感激。谢谢

[编辑] 格式化...

I'm trying to implement a comparison chart-like table, and a large list of selectable objects would work just perfectly, save for a few functionality changes that I need. I see that both of these have been addressed in previous questions, but neither of them provide complete solutions.

This question addressed the multiple select behavior by default, but only says 'I did it on my own' without providing anything. Looking at the internals of selectable, I see that if I play with the !event.metaKey condition I could probably get the behavior I'm looking for without too much trouble, but was wondering if anyone had a solution that didn't involve editing the internals.

Similarly, this page addresses the lasso toggle effect that I desired, but I'm not sure where in the code the lasso functionality was changed and as the rest of the script (the sortable functionality) is reported to not work in chrome or IE8 (link) and is outdated as this point, I'd rather not rely on the entire thing.

So if anyone could help me out with either of these, I'd appreciate it. Thanks

[Edit] Formatting...

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

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

发布评论

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

评论(1

独闯女儿国 2024-10-23 08:59:06

我确信有更好的方法来做到这一点,但这是我在可选择的 js 文件中所做的。

对于始终多重选择:

我添加了一个选项“alwaysMulti”(默认为 false)。然后,我将 !event.metaKey 的三个实例替换为 (!event.metaKey && !options.alwaysMulti) 以及 event 的两个实例。 metaKey(event.metaKey || options.alwaysMulti)

为了让选择套索切换所选状态,我从链接到的第二页找到了所需的更改。我还添加了一个选项“lassoToggle”(默认为 false)来触发此功能。在 _mouseDrag 中,有一个条件 if (hit),它会更改为以下内容:

    if (hit) {
                // SELECT
                selectee.deselect = false;
                if (selectee.selected || (options.lassoToggle && (selectee.startselected && event.metaKey)) {
                    selectee.$element.removeClass('ui-selected');
                    selectee.selected = false;
                    selectee.deselect = true;
                }
                if (selectee.unselecting) {
                    selectee.$element.removeClass('ui-unselecting');
                    selectee.unselecting = false;
                }
                if (!selectee.selecting && (!options.lassoToggle || !selectee.deselect) {
                    selectee.$element.addClass('ui-selecting');
                    selectee.selecting = true;
                    // selectable SELECTING callback
                    self._trigger("selecting", event, {
                        selecting: selectee.element
                    });
                }
                if(selectee.deselect && options.lassoToggle) {
                    selectee.$element.removeClass('ui-selecting');
                    selectee.selecting = false;
                    selectee.$element.addClass('ui-unselecting');
                    selectee.unselecting = true;
                    // selectable UNSELECTING callback
                    self._trigger("unselecting", event, {
                        unselecting: selectee.element
                    });
                }
            }

注意:多选的 event.metaKey 更改不在该代码示例中。

希望这对其他人有帮助!

I'm sure there's a better way to do this, but here's what I've did within the selectable js file.

For the always multi-selection:

I added an option 'alwaysMulti' (default false). Then I replaced the three instances of !event.metaKey with (!event.metaKey && !options.alwaysMulti) and the two instances of event.metaKey with (event.metaKey || options.alwaysMulti).

To get the selection lasso to toggle the selected status, I found the changes I needed from the second page I linked to. I also added an option 'lassoToggle' (default false) to trigger this functionality. Within _mouseDrag, there is a condition if (hit), it gets changed to the following:

    if (hit) {
                // SELECT
                selectee.deselect = false;
                if (selectee.selected || (options.lassoToggle && (selectee.startselected && event.metaKey)) {
                    selectee.$element.removeClass('ui-selected');
                    selectee.selected = false;
                    selectee.deselect = true;
                }
                if (selectee.unselecting) {
                    selectee.$element.removeClass('ui-unselecting');
                    selectee.unselecting = false;
                }
                if (!selectee.selecting && (!options.lassoToggle || !selectee.deselect) {
                    selectee.$element.addClass('ui-selecting');
                    selectee.selecting = true;
                    // selectable SELECTING callback
                    self._trigger("selecting", event, {
                        selecting: selectee.element
                    });
                }
                if(selectee.deselect && options.lassoToggle) {
                    selectee.$element.removeClass('ui-selecting');
                    selectee.selecting = false;
                    selectee.$element.addClass('ui-unselecting');
                    selectee.unselecting = true;
                    // selectable UNSELECTING callback
                    self._trigger("unselecting", event, {
                        unselecting: selectee.element
                    });
                }
            }

Note: The event.metaKey change for the multi-select isn't in that code sample.

Hopefully this helps someone else!

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