通过链接重定向不;我不在jstree中工作
redirection by link doesn't work in jstree
在jstree jquery插件中,我希望当用户点击一个节点时,被重定向到点击链接的href。
这是传递给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作者。
但当点击节点上的链接时,出现了此错误:
Uncaught TypeError: Cannot read property 'href' of undefined
什么是问题,什么是正确的解决方案?
我可以找到解决方案。
通过尝试下面的代码,我的问题得到了解决。
on("changed.jstree", function (e, data) {
if(data.node) {
document.location = data.node.a_attr.href;
}
});
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 在jstree中,如何将指定的节点集中到大型树上
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- 通过链接重定向不;我不在jstree中工作
- 我可以在 MVC 3.0 中获得一个工作 Asp.NET jsTree 4 示例,并异步加载节点
- JSTREE open_node不在子节点上工作
- Jstree:创建新节点不工作
- Jstree 3.0.0上下文菜单右键不工作.显示TypeError: vakata_context.element.h
- jstree链接在IE8中不工作
- jstree无法在IE9上工作