
比如,服务器组装好的json数据:
{
id:'001',
nodeMsg:'节点1'
}
这个是ajax成功之后的回调
function(xhr){
var o = eval('(' + xhr.responseText + ')')
alert(o.id + ':' + o.nodeMsg)
}
1. 既然你使用了 ui-router,说明你的应用是 单页程序,既然是单页程序,首先要考虑动态路由是否有必要?只要根据用户角色 显示该角色可以访问的菜单即可,在每次路由切换的时候判断下是否有访问此路由的权限,没有就跳转到指定页面即可;2. 至于你说的动态加载 是想根据用户角色动态返回指定角色的路由、模板、controller js吗?一般项目把所有的js和模板都打包压缩成一个js,反而效果更好;
3. 如果你非要想根据角色动态生成路由,可以在angular还没有启动的时候获取该用户角色的所有路由(也可以说菜单),然后循环菜单 通过 ui-router 动态加入即可;
4. 这样只有路由是动态载入了,关于每个路由对应的js,如果你也想实现 动态载入的话,估计就需要使用类似 requirejs 的东西,比如 marcoslin/angularAMD · GitHub 或者 atian25/angular-lazyload · GitHub 或者自己写一个也可以,原理就是在 路由的 resolve 中加载对应的js
5. 模板感觉就不需要动态加载了吧,因为使用ng,模板都是前端模板,如果要根据角色动态生成模板岂不是变成服务端渲染了。
jsp动态树形菜单须用到递归算法,比如在数据库有张表,parent表,parent的字段有id,name,depth,leve,ID自增,depth设置为级数,如这条数据最大,为0,如为字菜单就为1,而leve就指定它父节点的id,给段代码自己可以摸索下 public Vector getModuleTree(){
Vector pclass = new Vector()
try
{
stmt =con.createStatement()
String sql = "select * from Module where parentid = 0"
rs = stmt.executeQuery(sql)
Module cvo = null
while(rs.next())
{
cvo = new Module()
cvo.setModule_id(rs.getInt("Module_id"))
cvo.setModule_name(rs.getString("Module_name"))
cvo.setModule_url(rs.getString("Module_url"))
cvo.setParentid(rs.getInt("parentid"))cvo.setRootid(rs.getInt("rootid"))cvo.setDepth(rs.getInt("depth"))pclass.add(cvo)
}
for (int i = 0i <pclass.size()i++)
{
Module pcvo = (Module) pclass.get(i)
ShowTreeMenu(pcvo)
}
con.commit() } catch (SQLException e)
{
e.printStackTrace()
} finally
{
try
{
if(rs!=null)
{
rs.close()
}
if(stmt!=null)
{
stmt.close()
}
if(con!=null)
{
con.close()
}
}
catch (SQLException e)
{
e.printStackTrace()
}
}
return classList
}
public void ShowTreeMenu(Module c)
{
Module ccvo = null
String sql = "select * from Module where parentid = " + c.getModule_id()
Vector cclass = new Vector()
try
{
Module cvotemp
stmt =con.createStatement()
rs = stmt.executeQuery(sql)
while(rs.next())
{
cvotemp = new Module()
cvotemp.setModule_id(rs.getInt("Module_id"))
cvotemp.setModule_name(rs.getString("Module_name"))
cvotemp.setModule_url(rs.getString("Module_url"))
cvotemp.setParentid(rs.getInt("parentid"))cvotemp.setRootid(rs.getInt("rootid"))cvotemp.setDepth(rs.getInt("depth"))cclass.add(cvotemp)
}
System.out.println(cclass.size()+"(((((((((((((((((((((((((9")
if (cclass.size() >0)
{
c.setHasChild("have")
classList.add(c)
for (int j = 0j <cclass.size()j++)
{
ccvo = (Module) cclass.get(j)
ShowTreeMenu(ccvo)
}} else
{
classList.add(c)
}
} catch (SQLException e)
{
e.printStackTrace()
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)