2010-03-24 55 views
4

我在我们的应用程序的几个页面上使用相同的dijit.Tree视图,并且希望将Cookie保存为服务器名称而不是文件夹名称。
现在我已经有了3页和3个饼干,每个饼干都拥有自己关于树状态的信息,这有点烦人。为所有页面设置dijit.Tree cookie

任何方式来实现这一目标?我在API上唯一发现的Cookie是我可以设置cookieName并打开/关闭Cookie。

回答

4

似乎Tree.js不会让您设置cookie的属性。所以我不得不改写为Tree_saveState()方法:

var treeControl = new dijit.Tree({ 
    model: treeModel, 
    showRoot: false, 
    openOnClick: false, 
    cookieName: "OrganizationUnitTreeState", 
    _saveState: function(){ 
     // summary: 
     // Create and save a cookie with the currently expanded nodes identifiers 
     // Overre the default saveState function, so we can set the cookie path 
     if(!this.persist){ 
      return; 
     } 
     var ary = []; 
     for(var id in this._openedItemIds){ 
      ary.push(id); 
     } 
     dojo.cookie(this.cookieName, ary.join(","), {expires:365, path:"/"}); 
    }, 
    /* Many more methods */ 
}); 

它的代码的最后一行有没有做的伎俩。 dojo.cookie()需要一个键/值对的列表,它将被转换成cookie属性,所以如果你想要设置任何其他属性,这就是你要做的。

+0

非常有用。 '如果这是一个用于改变站点范围内的树持久性的官方API,那会很好。您可以提交增强权证。 – 2010-12-21 09:54:36

相关问题