javascript - Fancytree 不可见,具有 ui-helper-hidden 类

标签 javascript jquery fancytree

我刚刚开始使用 fancytree 2.6.0,并通过 Web 服务请求填充它。

我的问题是所有节点都存在,但被 ui-helper-hidden 类设为不可见。我已经进行了临时修复: $(rootNode.ul).removeClass('ui-helper-hidden');但我确信我错过了一些东西。

脚本和CSS:

<link href="Scripts/jquery-plugins/fancytree-2.6.0/src/skin-themeroller/ui.fancytree.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.11.1/jquery-1.11.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.11.1/jquery-migrate-1.2.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.11.2/jquery-ui.js" type="text/javascript"></script>
<script src="Scripts/jquery-plugins/fancytree-2.6.0/src/jquery.fancytree.js" type="text/javascript"> </script>
<script src="Scripts/jquery-plugins/fancytree-2.6.0/src/jquery.fancytree.themeroller.js" type="text/javascript"> </script>

代码:

$('#selectedClausesDiv').fancytree();

$.when(
    $.getJSON("Handlers/GetQuotationHandler.ashx?jsoncallback=?", { quoteReference: quoteReference, quoteVersion: quoteVersion })
).then(function (data) {
    if (data.ErrorCode == 0 && data.Quotation != null) {
        var rootNode = $("#selectedClausesDiv").fancytree("getRootNode");
        $.each(data.Quotation.Covers, function (index, item) {
            addCover(rootNode, item);
        });

        // FIXME: why is this necessary ??
        // $(rootNode.ul).removeClass('ui-helper-hidden');
    }
});

function addCover(rootNode, cover) {
    var coverId = 'selected_' + cover.BusinessClassId + '_' + cover.CoverId;

    var coverNode = rootNode.addChildren({
        title: cover.Name,
        tooltip: "This folder and all child nodes were added programmatically.",
        folder: true
    });
}

生成的html:

<div class="grid_13 alpha omega" id="selectedClausesDiv">
    <ul class="ui-fancytree fancytree-container ui-fancytree-source ui-helper-hidden" tabindex="0">
        <li class="">
            <span class="fancytree-node fancytree-folder fancytree-exp-n fancytree-ico-cf">
                <span class="fancytree-expander"/>
                <span class="fancytree-icon"/>
                <span title="This folder and all child nodes were added programmatically." class="fancytree-title">P&amp;I Owned</span>
            </span>
        </li>
        <li class="fancytree-lastsib">
            <span class="fancytree-node fancytree-folder fancytree-lastsib fancytree-exp-nl fancytree-ico-cf">
                <span class="fancytree-expander"/>
                <span class="fancytree-icon"/>
                <span title="This folder and all child nodes were added programmatically." class="fancytree-title">P&amp;I Extended Cargo</span>
            </span>
        </li>
    </ul>
</div>

最佳答案

如果没有提供数据源,Fan​​cytree将自动隐藏根元素。

如果您使用 API 添加数据且没有初始源,则提供空白的 source 选项将阻止 Fancytree 隐藏根元素。

$("#tree").fancytree({
    source: []
});

关于javascript - Fancytree 不可见,具有 ui-helper-hidden 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27397982/

相关文章:

JavaScript FancyTree : is it possible to distinguish between the selection of a node and the action of expanding it.

javascript - 如何在删除节点后使用 fancytree 小部件(Yii2)重新加载整个树

javascript - 如何在 $scope 中分离 get http 请求中的 json 对象?

javascript - iPhone 日期字段 - 更改日期格式

javascript - 在 Label 悬停时显示工具提示?

jquery - 如何动态替换 html 文本?

jquery - 单击侧边栏中的元素时防止主窗口滚动

javascript - 将 fancytree 节点拖到外部 droppable

javascript - chrome....onBeforeRequest...() URL 列表未按预期运行

javascript - 如何给 map 添加onClick `leaflet`