gpt4 book ai didi

javascript - 如何在 elFinder 中检测多项选择

转载 作者:行者123 更新时间:2023-11-30 17:45:28 26 4
gpt4 key购买 nike

我向 elFinder 添加了一个新的工具栏按钮和一个新的上下文菜单项。

效果不错,但只有在选择一个普通文件 时才应启用此项目。所以当没有选择文件时应该变暗,当选择多个文件或选择目录时应该变暗。

我在 elFinder.prototype.commands.mycmd 中了解到我应该将 this.getstate 返回值设置为:

  • 0 如果应该启用工具栏/上下文菜单项,并且
  • -1 如果它应该被禁用

所以,现在有这个:

电子

Finder.prototype.commands.mycmd= function() {

var self = this,
fm = self.fm;

self.disableOnSearch = true;

self.title = 'mycmd';

self.getstate = function() {
// need help here to add the "directory is selected check"
return fm.selected().length == 1 ? 0 : -1;
}

self.exec = function() {
alert("hello");
}
}

不幸的是,我只懂 Perl,所以我很难挖掘所有 elFinder 的 javascript 代码来弄清楚如何掌握条件。

认识elFinder 足够深的人来帮助我解决这个问题吗?

最佳答案

只需在 elFinder 的 download.js 中找到解决方案即可。

这有效 - 至少现在.. ;)

elFinder.prototype.commands.mycmd= function() {

var self = this,
fm = self.fm;

self.disableOnSearch = true;
filter = function(hashes) {
return $.map(self.files(hashes), function(f) { return f.mime == 'directory' ? null : f });
};

self.title = 'mycmd';

self.getstate = function() {
var sel = self.fm.selected(),
cnt = sel.length;
return !self._disabled && cnt == 1 && cnt == filter(sel).length ? 0 : -1;
}

self.exec = function() {
alert("hello");
}
}

关于javascript - 如何在 elFinder 中检测多项选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com