Javascript 如何使用jquery删除treeview子节点
我有一个树状视图,如下所示,我需要根据用户从列表中删除一个子项。谁能告诉我怎么把孩子从树上移开吗Javascript 如何使用jquery删除treeview子节点,javascript,jquery,asp.net-mvc,asp.net-mvc-3,Javascript,Jquery,Asp.net Mvc,Asp.net Mvc 3,我有一个树状视图,如下所示,我需要根据用户从列表中删除一个子项。谁能告诉我怎么把孩子从树上移开吗 var treedata = [ { label: 'Floor', type: 'Country', children: [ { label: 'Bangalore', type: 'Location',
var treedata = [
{
label: 'Floor', type: 'Country',
children: [
{
label: 'Bangalore', type: 'Location',
children: [{ label: 'Technopolis', type: 'facility', id: 1 }, { label: 'Ecity Tower-2', type: 'facility', id: 2 }, { label: 'Bagmane', type: 'facility', id: 3 }, { label: 'Cyber Park', type: 'facility', id: 4 }]
},
{
label: 'Hyderabad', type: 'Location',
children: [{ label: 'Hitech City ', type: 'facility', id: 5 }, { label: 'Cyber City', type: 'facility', id: 6 }]
},
{
label: 'Chennai', type: 'Location',
children: [{ label: 'XXX', type: 'facility', id: 7 }]
},
{
label: 'Mumbai', type: 'facility', id: 8
}
]
},
{
label: 'Role Administration', type: 'Role',
children: [{ label: 'Assign Role', type: 'Role', id: 1 }]
},
{
label: 'Hoteling Admin', type: 'Hoteling',
children: [{ label: 'Hoteling', type: 'Hoteling', id: 1 }]
}
];
上面是我的jquery树数据。如果用户是普通用户,我想通过检查用户角色来删除角色管理
任何人都可以帮助我如何使用jquery
谢谢您可以使用$.grep()
根据需要的任何条件将数组筛选为新数组
var userRole='normal';
if( userRole === 'normal'){
treeview = $.grep(treeview, function(item){
return item.label != 'Role Administration';
});
}
用户角色节点在哪里?