我有一个Javascript应用程序,我需要转义像“<”这样的字符和“>”在一个字符串中。
这看起来是一个理想的解决方案:
https://github.com/reduxjs/react-redux/blob/master/docs/api.md
library(shiny) library(shinydashboard) myTabs = lapply(X = 1: 3, FUN=infoBox, title=paste("tabPanels")); for (i in 1:3){ myTabs[[i]]$attribs$`data-value` <- i+1 myTabs[[i]]$attribs$title <- paste("tabPanels", i) myTabs[[i]]$attribs$class <- "tab-pane fa-fw" myTabs[[i]]$attribs$'data-icon-class' <- paste0("fa fa-battery-",i+1) } nlp <- do.call(navlistPanel, myTabs) header <- dashboardHeader(disable = TRUE) sidebar <- dashboardSidebar(disable = TRUE) body <- dashboardBody( nlp ) server <- function(input, output) { output$view <- renderTable({apps_directory} , sanitize.text.function = function(x) x) } ui <- dashboardPage(header = header, sidebar = sidebar, body = body ) shinyApp(ui, server)
或使用的简短替代品 How to escape HTML 构造
function escapeHTML(str){ var p = document.createElement("p"); p.appendChild(document.createTextNode(str)); return p.innerHTML; }
问:这实际上是否将“p”(及相关文本)添加到我的DOM?
问:如果我要保存的所有内容都是转义字符串,我是否需要“removeChild()”或任何其他“清理”?
答案 0 :(得分:4)
A1:不,如果该函数也调用了document.body.appendChild(p);
A2:不,你可以从A1猜测。函数返回后,其局部变量被丢弃,p
变得无法访问,最终将被垃圾收集。