因此,我有一個工作正常的FancyTree。當用戶移動到另一個頁面時,我想保持樹的狀態。我正在關注這個鏈接來實現這一點; http://wwwendt.de/tech/fancytree/demo/sample-ext-persist.html#FancyTree - 只加載頁面刷新後的持久狀態
我正在使用Ajax加載我的所有頁面,當我使用Ctrl + F5
重新加載網站並導航到帶有樹的頁面時,以前狀態從本地存儲加載。這很好。
當我刷新整個頁面:
但是當我去到另一個網頁使用Ajax和回來與樹的頁面時,它不會加載以前的狀態。
當我加載使用Ajax的視圖:
這是我的代碼:
var glyph_opts = {
map: {
doc: "fa fa-truck",
docOpen: "fa fa-truck",
checkbox: "glyphicon glyphicon-unchecked",
checkboxSelected: "glyphicon glyphicon-check",
checkboxUnknown: "glyphicon glyphicon-share",
dragHelper: "glyphicon glyphicon-play",
dropMarker: "glyphicon glyphicon-arrow-right",
error: "glyphicon glyphicon-warning-sign",
expanderClosed: "glyphicon glyphicon-plus-sign",
expanderLazy: "glyphicon glyphicon-plus-sign",
expanderOpen: "glyphicon glyphicon-minus-sign",
folder: "glyphicon glyphicon-folder-close",
folderOpen: "glyphicon glyphicon-folder-open",
loading: "glyphicon glyphicon-refresh"
}
};
$("#tree").fancytree({
extensions: ["glyph", "filter", "persist"],
persist: {
expandLazy: true,
// fireActivate: true, // false: suppress `activate` event after active node was restored
overrideSource: true, // true: cookie takes precedence over `source` data attributes.
store: "auto" // 'cookie', 'local': use localStore, 'session': sessionStore
},
source: $.ajax({
url: '@Url.Action("CompaniesTree", "Dashboard")',
type: "GET",
dataType: "json"
}),
activate: function (event, data) {
if (data.node.data.GroupType === 4) {
var model = {
key: data.node.key,
data: data.node.data
};
}
return true;
},
iconClass: function (event, data) {
if (data.node.data.GroupType === 1) {
return "fa fa-desktop";
}
if (data.node.data.GroupType === 2) {
return "fa fa-sitemap";
}
},
selectMode: 2,
init: function (event, data) {
data.tree.debug(event.type, data);
},
restore: function (event, data) {
data.tree.debug(event.type, data);
},
loadChildren: function (event, data) {
data.node.debug(event.type, data);
},
quicksearch: true,
filter: {
//http://wwwendt.de/tech/fancytree/demo/sample-ext-filter.html#
//autoApply: true, // Re-apply last filter if lazy data is loaded
counter: false, // Show a badge with number of matching child nodes near parent icons
fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
hideExpandedCounter: true, // Hide counter badge, when parent is expanded
mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
},
glyph: glyph_opts,
lazyLoad: function (event, data) {
var model = {
key: data.node.key,
data: data.node.data
};
$.ajax({
url: '@Url.Action("ChildItems", "Dashboard")',
type: "POST",
async: false,
contentType: "application/json",
data: JSON.stringify(model),
success: function (response) {
data.result = response;
}
});
}
});
var tree = $("#tree").data("ui-fancytree").getTree();
我甚至檢查會話存儲並查看花式樹狀態的數據被保存 - 沒有錯誤Console
在您加載頁面的位置發佈ajax調用可能有助於查找問題。當頁面被加載時,你如何調用你的fancytree代碼? –
該代碼已發佈在問題 –
我的意思是您用於在頁面之間導航的代碼。我只能看到初始化樹的代碼 –