【问题标题】:Getting id or name of folder in fuelux tree在fuelux树中获取文件夹的ID或名称
【发布时间】:2016-03-18 10:12:38
【问题描述】:

我正在尝试获取燃料树中所选文件夹的 ID 或名称,但无法完成。

我的树是经典的文件夹/文件类型树,我希望在单击文件时能够看到文件夹的 ID。

这是我的树数据源

var treeDataSource = new DataSourceTree({
                data: [
                    { name: 'Elektronik Belgelerim', type: 'folder', 'icon-class': 'blue', additionalParameters: { id: 'F1' } },
                    { name: 'Gelen Kutusu', type: 'folder', 'icon-class': 'blue', additionalParameters: { id: 'F2' } },
                    { name: 'Giden Kutusu', type: 'folder', 'icon-class': 'blue', additionalParameters: { id: 'F3' } },
                    { name: 'Çöp Kutusu', type: 'folder','icon-class':'green', additionalParameters: { id: 'I1' } },
                    //{ name: 'Çöp Kutusu', type: 'item', 'icon-class': 'success', additionalParameters: { id: 'F4' } },

                    //{ name: 'Reports', type: 'item', additionalParameters: { id: 'I1' } },
                    //{ name: 'Finance', type: 'item', additionalParameters: { id: 'I2' } }
                ],
                delay: 400
            });

树的js函数在tree-custom.js中像这样开始

var e = function (e, i) {
        this.$element = t(e), this.options = t.extend({}, t.fn.tree.defaults, i), this.$element.on("click", ".tree-item", t.proxy(function (t) {
            this.selectItem(t.currentTarget)
        }, this)), this.$element.on("click", ".tree-folder-header", t.proxy(function (t) {
            this.selectFolder(t.currentTarget)
        }, this)), this.render()
    };

这是我在 trree-custom.js 中再次添加文件夹下的链接的地方。我知道非常原始,但这就是我目前的技能所能做的。我添加的部分在引号之间。 Rest 带有 Beyondadmin 主题,看起来像通常的燃料。

selectFolder: function (e) {
            //alert("testselectFolder");
            //
            //alert($('#myTree').tree({ dataSource: dataSource }));

            var i, n, r, o = t(e),
                s = o.parent(),
                a = s.find(".tree-folder-content"),
                l = a.eq(0);
            //-----------------------------------------------
            var li = $('<li>');
            var TcgbLink = $('<a href=/E-Belge/Main/Folder/Inbox/?Type=1&DocumentTypeId=3>e-TCGB</div>' +"</br>");
            var FaturaLink = $('<a href=/E-Belge/Main/Folder/Inbox/?Type=1&DocumentTypeId=4>e-Fatura</div>' + "</br>");
            var Dolasim = $('<a href=>e-Dolasim Belgesi</div>');
            li.append(FaturaLink);
            a.append(li);
            li.append(TcgbLink);
            a.append(li);
            li.append(Dolasim);
            a.append(li);
            //-----------------------------------------------
            o.find(".fa.fa-folder").length ? (i = "opened", n = ".fa.fa-folder", r = "fa fa-folder-open", l.show(), a.children().length || this.populate(o)) : (i = "closed", n = ".fa.fa-folder-open", r = "fa fa-folder", l.hide(), this.options.cacheItems || l.empty()), s.find(n).eq(0).removeClass("fa fa-folder fa-folder-open").addClass(r), this.$element.trigger(i, o.data())

        },

现在所有 4 个文件夹下都会生成这些链接。我希望能够获取文件夹的 id(或名称,最好是 Id),以便将新的 Type 参数分配给 querystring。

到目前为止,我尝试使用 this.data.id 访问 id 无济于事。

【问题讨论】:

    标签: javascript jquery tree fuelux


    【解决方案1】:

    建议不要在 selectFolder 回调中注入文件夹的子文件夹,而是通过 dataSource 回调添加子文件夹(如本示例代码:http://getfuelux.com/javascript.html#tree-usage-javascript)。

    当您单击树节点时,dataSource 的第一个参数是“父数据”(第二个参数是您发送新的子数据数组的回调)。

    这样您就可以使用selected event 来获取您的ID,因为它会获取传递给它的jQuery 数据。

    【讨论】:

    • 上面的解释有没有你不明白的地方?
    • 实际上你的回答对我帮助很大,让我以不同的方式思考,我解决了将子节点名称更改为 href 标签的问题。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    相关资源
    最近更新 更多