我有以下JSON树结构:
[
{
"expanded":"false",
"key":"_23",
"title":"Politics",
"data":{
"id":"23",
"name_en":"Politics",
"description_en":"",
"seo_title_en":"",
"seo_description_en":"",
"name_sr":"Politika",
"description_sr":"",
"seo_title_sr":"",
"seo_description_sr":"",
"slug_en":"politics",
"slug_sr":"politika"
},
"children":[
{
"key":"_24",
"title":"Domestic politics",
"data":{
"id":"24",
"name_en":"Domestic politics",
"description_en":"",
"seo_title_en":"",
"seo_description_en":"",
"name_sr":"Doma\u0107a politika",
"description_sr":"",
"seo_title_sr":"",
"seo_description_sr":"",
"slug_en":"domestic-politics",
"slug_sr":"domaca-politika"
}
}
]
},
{
"expanded":"false",
"key":"_21",
"title":"Sport",
"data":{
"id":"21",
"name_en":"Sport",
"description_en":"",
"seo_title_en":"",
"seo_description_en":"",
"name_sr":"Sport",
"description_sr":"",
"seo_title_sr":"",
"seo_description_sr":"",
"slug_en":"sport",
"slug_sr":"sport"
},
"children":[
{
"key":"_22",
"title":"Football",
"data":{
"id":"22",
"name_en":"Football",
"description_en":"",
"seo_title_en":"",
"seo_description_en":"",
"name_sr":"Fudbla",
"description_sr":"",
"seo_title_sr":"",
"seo_description_sr":"",
"slug_en":"football",
"slug_sr":"fudbla"
}
}
]
}
]
如您所见,第一级的两个节点已扩展设为false。但那些没有在树上倒塌。
我从AJAX请求加载树。这是init代码:
$("#news-categories-table").fancytree({
icon: false,
checkbox: false,
titlesTabbable: true,
source: {
url: SITE_URL + "news_categories/get_tree",
cache: false
},
extensions: ["table", "dnd"],
table: {
nodeColumnIdx: 1 // render node expander, icon, and title to this column (default: #0)
},
dnd: {
autoExpandMS: 400,
draggable: { // modify default jQuery draggable options
zIndex: 1000,
scroll: false,
containment: "parent",
revert: "invalid"
},
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
dragStart: function(node, data) {
return true;
},
dragEnter: function(node, data) {
return true;
},
dragExpand: function(node, data) {
return true;
},
dragOver: function(node, data) {
return true;
},
dragLeave: function(node, data) {
return true;
},
dragStop: function(node, data) {
return true;
},
dragDrop: function(node, data) {
data.otherNode.moveTo(node, data.hitMode);
}
},
renderColumns: function(event, data) {
var node = data.node,
$tdList = $(node.tr).find(">td");
// td 1 value is edit icon
$tdList.eq(0).html(node.data.id);
}
});
这可以以某种方式解决吗?我之前使用过fancytree,旧版本没问题。扩展的错误节点在加载树时折叠。
这也是截图。
答案 0 :(得分:0)
展开的选项需要一个布尔值。尝试传递
# A function to add 1 to all numbers in a column
add_one <- function(Col, dt){
dt[, Col] <- dt[, Col] + 1
return(dt)
}
# Get the column names
Col_vec <- colnames(df)[2:ncol(df)]
# Apply the add_one function
df_list <- lapply(Col_vec, add_one, dt = df)
# Combine all results
df2 <- dplyr::bind_rows(df_list)
而不是
"expanded": false,