0
在jstree jquery plugin,我想當用戶點擊一個節點,被重定向到單擊鏈接的href。通過鏈接重定向不工作在jstree
這是傳遞給jstree數據:
[
{
"id": 4,
"contentable_id": 8,
"contentable_type": "App\\Unit",
"text": "واحد جدید",
"parent_id": "#",
"icon": "fa fa-file-text-o",
"a_attr": {
"href": "./unit/8/edit"
}
},
{
"id": 5,
"contentable_id": 5,
"contentable_type": "App\\Unit",
"text": "واحد من ",
"parent_id": "#",
"icon": "fa fa-file-text-o",
"a_attr": {
"href": "./unit/5/edit"
}
}
]
及以下jstree調用代碼:
$treeview.jstree({
"core": {
'data': {
'url': targetUrl
},
"check_callback": true,
"animation": 200,
"dblclick_toggle": false,
"keep_selected_style": false
},
"plugins": ["dnd", "contextmenu"],
"contextmenu": {
"select_node": false,
"show_at_node": false,
}
}).on('changed.jstree', function (e, data) {
document.location = data.instance.get_node(data.selected[0], true).a_attr.href;
});
正如你看到的我用改變 jstree事件來捕獲單擊事件和重定向因爲建議使用jstree作者here。
但是,當點擊一個節點上的一個鏈接此錯誤發生在:
Uncaught TypeError: Cannot read property 'href' of undefined
是什麼問題,什麼是正確的解決辦法嗎?