问题描述
问题是这样的:当用户登录成功后,用变量保存之,然后在各个控件中使用。问题有二:一、用户登陆成功后,用什么保存用户ID? 我目前用cookies,这方法可用,但是不知道大家有没有更好的办法二、我用cookies读到值后,但是当要在控件中使用的时候,读取不到值.具体代码如下:布局代码:var cookiesuid = "";Ext.onReady(function() { // 修改该空白背景图的路径,指向你服务端一个有效的图片路径。 Ext.BLANK_IMAGE_URL = '/extjs/resources/images/default/s.gif'; // NOTE: This is an example showing simple state management. During development, // it is generally best to disable state management as dynamically-generated ids // can change across page loads, leading to unpredictable results. The developer // should ensure that stable state ids are set for stateful components in real apps. var cp = new Ext.state.CookieProvider(); Ext.state.Manager.setProvider(cp); cookiesuid = cp.get("cookiesuid"); if (cookiesuid == "") { Ext.Msg.alert('提示', '会话过期,请重新登陆!', function(btn, text) { if (btn == 'ok') { var redirect = 'Default.aspx'; window.location = redirect; } }); } var viewport = new Ext.Viewport({ layout: 'border', items: [ // create instance immediately new Ext.BoxComponent({ region: 'north', height: 60, // give north and south regions a height contentEl: 'north' }), new Ext.BoxComponent({ region: 'south', height: 25, // give north and south regions a height contentEl: 'south' }), tree, centertab] });只是取了前面一段。onready函数还没有关闭。然后继续定义树 // 左边的菜单 var tree = new Ext.tree.TreePanel({ title: '功能菜单', region: "west", autoScroll: true, enableTabScroll: true, collapsible: true, collapsed: false, iconCls: 'plugin', split: true, rootVisible: false, lines: false, width: 220, minSize: 220, maxSize: 220, loadMask: true, loader: new Ext.tree.TreeLoader({ baseParams: { op: 'getmenunode', uid: cookiesuid }, dataUrl: '../ashx/menu.ashx' }), root: new Ext.tree.AsyncTreeNode({ id: '0', // 注意这个0是约定 level: '0', expanded: true, text: '菜单', leaf: false }) });因为我的树是根据用户ID不同而不同的,但是在这里传值传不进去,请问各位高人,如何解决这个问题呀?
解决方案
loader: new Ext.tree.TreeLoader({ dataUrl: '../ashx/menu.ashx' listeners:{ 'beforeload':function(treeLoader, node){ treeLoader.baseParams.op=getmenunode; treeLoader.baseParams.uid= cookiesuid; } } }), 试试上面的 应该可以