gpt4 book ai didi

javascript - 如何删除jsTreeR中用户折叠指定父节点的选项?

转载 作者:行者123 更新时间:2023-12-02 01:24:15 25 4
gpt4 key购买 nike

关于如何仅使 jsTreeR 包中的特定节点不可折叠,而所有其他节点保持可折叠(如下所示),有什么建议吗?代码发布在插图下方。

enter image description here

代码:

library(jsTreeR)
library(shiny)

nodes <- list(
list(
text = "Menu",
state = list(opened = TRUE),
children = list(
list(text = "Dog",type = "moveable",state = list(disabled = TRUE)),
list(text = "Cat",type = "moveable",state = list(disabled = TRUE))
)
),
list(text = ">> Drag here <<",type = "target",state = list(opened = TRUE))
)

dnd <- list(
always_copy = TRUE,
inside_pos = "last",
is_draggable = JS(
"function(node) {",
" return node[0].type === 'moveable';",
"}"
)
)

mytree <- jstree(
nodes, dragAndDrop = TRUE, dnd = dnd,
types = list(moveable = list(), target = list())
)

ui <- fluidPage(
# tags$head(tags$script(HTML(script))),
fluidRow(jstreeOutput("mytree"))
)

server <- function(input, output, session){output[["mytree"]] <- renderJstree(mytree)}

shinyApp(ui, server)

最佳答案

我会直接添加click第一个处理程序 <i>节点,它使用 stopPropagation以防止单击事件冒泡并从而关闭父级。您需要延迟click的分配handler,b/c 在渲染时节点(以及带有箭头的 <i> 元素)尚未设置。外环one当节点准备好时,处理程序将触发,这就是我们分配 click 的地方处理程序。

mytree %>%
htmlwidgets::onRender("
function (el) {
$(el).one('ready.jstree', function() {
// need to wait until all nodes are loaded to assigne event listener
$(this).find('i').first().on('click', (evt) => evt.stopPropagation())
});
}")

关于javascript - 如何删除jsTreeR中用户折叠指定父节点的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75174485/

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