Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 树没有节点持久性_Javascript_Dojo - Fatal编程技术网

Javascript 树没有节点持久性

Javascript 树没有节点持久性,javascript,dojo,Javascript,Dojo,在我的ASP.NET项目中,我尝试使用一些DojoUI元素。我的第一次尝试是一个类似于dojo文档中所示的树。但在刷新浏览器页面后,树拒绝保留扩展节点的状态 require([ "dojo/ready", "dojo/_base/window", "dojo/store/Memory", "dijit/tree/ObjectStoreModel", "dijit/Tree" ], function (ready, win, Memo

在我的ASP.NET项目中,我尝试使用一些DojoUI元素。我的第一次尝试是一个类似于dojo文档中所示的树。但在刷新浏览器页面后,树拒绝保留扩展节点的状态

require([
            "dojo/ready", "dojo/_base/window", "dojo/store/Memory",
            "dijit/tree/ObjectStoreModel", "dijit/Tree"
        ], function (ready, win, Memory, ObjectStoreModel, Tree) {

            // Create test store, adding the getChildren() method required by ObjectStoreModel
            var myStore = new Memory({
                data: [
                    { id: 'world', name: 'The earth', type: 'planet', population: '6 billion' },
                    { id: 'AF', name: 'Africa', type: 'continent', parent: 'world'
                    },
                        { id: 'EG', name: 'Egypt', type: 'country', parent: 'AF' },
                        { id: 'KE', name: 'Kenya', type: 'country', parent: 'AF' },
                            { id: 'Nairobi', name: 'Nairobi', type: 'city', parent: 'KE' },
                            { id: 'Mombasa', name: 'Mombasa', type: 'city', parent: 'KE' },
                        { id: 'SD', name: 'Sudan', type: 'country', parent: 'AF' },
                            { id: 'Khartoum', name: 'Khartoum', type: 'city', parent: 'SD' },
                    { id: 'AS', name: 'Asia', type: 'continent', parent: 'world' },
                        { id: 'CN', name: 'China', type: 'country', parent: 'AS' },
                        { id: 'IN', name: 'India', type: 'country', parent: 'AS' },
                        { id: 'RU', name: 'Russia', type: 'country', parent: 'AS' },
                        { id: 'MN', name: 'Mongolia', type: 'country', parent: 'AS' },
                    { id: 'OC', name: 'Oceania', type: 'continent', population: '21 million', parent: 'world' },
                    { id: 'EU', name: 'Europe', type: 'continent', parent: 'world' },
                        { id: 'DE', name: 'Germany', type: 'country', parent: 'EU' },
                        { id: 'FR', name: 'France', type: 'country', parent: 'EU' },
                        { id: 'ES', name: 'Spain', type: 'country', parent: 'EU' },
                        { id: 'IT', name: 'Italy', type: 'country', parent: 'EU' },
                    { id: 'NA', name: 'North America', type: 'continent', parent: 'world' },
                    { id: 'SA', name: 'South America', type: 'continent', parent: 'world' }
                ],
                getChildren: function (object) {
                    return this.query({ parent: object.id });
                }
            });

            // Create the model
            var myModel = new ObjectStoreModel({
                store: myStore,
                query: { id: 'world' }
            });

            // Create the Tree.   Note that all widget creation should be inside a dojo.ready().
            ready(function () {
                var tree = new Tree({
                    model: myModel,
                    persist: true
                });
                tree.placeAt("tree2");
                tree.startup();
            });
        });
    </script>

    <div id="tree2"></div>
需要([
“dojo/ready”、“dojo/_base/window”、“dojo/store/Memory”,
“dijit/tree/ObjectStoreModel”、“dijit/tree”
],函数(就绪、win、内存、ObjectStoreModel、树){
//创建测试存储,添加ObjectStoreModel所需的getChildren()方法
var myStore=新内存({
数据:[
{id:'世界',名称:'地球',类型:'行星',人口:'60亿'},
{id:'AF',name:'Africa',type:'constance',parent:'world'
},
{id:'EG',name:'埃及',type:'country',parent:'AF'},
{id:'KE',name:'Kenya',type:'country',parent:'AF'},
{id:'Nairobi',name:'Nairobi',type:'city',parent:'KE'},
{id:'Mombasa',name:'Mombasa',键入:'city',父项:'KE'},
{id:'SD',name:'Sudan',type:'country',parent:'AF'},
{id:'Khartoum',name:'Khartoum',键入:'city',父项:'SD'},
{id:'AS',name:'Asia',type:'constance',parent:'world'},
{id:'CN',name:'China',type:'country',parent:'AS'},
{id:'IN',name:'India',键入:'country',parent:'AS'},
{id:'RU',name:'rusia',键入:'country',父项:'AS'},
{id:'MN',name:'蒙古',type:'country',parent:'AS'},
{id:'OC',名称:'Oceania',类型:'Continental',人口:'2100万',父母:'world'},
{id:'EU',name:'Europe',type:'continent',parent:'world'},
{id:'DE',name:'dermany',type:'country',parent:'EU'},
{id:'FR',name:'France',type:'country',parent:'EU'},
{id:'ES',name:'spaine',type:'country',parent:'EU'},
{id:'IT',name:'Italy',type:'country',parent:'EU'},
{id:'NA',name:'North America',type:'constance',parent:'world'},
{id:'SA',name:'South America',键入:'Continental',父级:'world'}
],
getChildren:函数(对象){
返回this.query({parent:object.id});
}
});
//创建模型
var myModel=新的ObjectStoreModel({
商店:myStore,
查询:{id:'world'}
});
//创建树。注意,所有小部件的创建都应该在dojo.ready()中。
就绪(函数(){
var-tree=新树({
型号:myModel,
坚持:对
});
tree.placeAt(“tree2”);
tree.startup();
});
});

Cookies被激活。我希望这一切发生在客户方。使用chrome、firefox和IE进行了尝试。

树的id丢失。有了id,它就可以工作了:

var tree = new Tree({
    id: "yourtree",
    model: myModel,
    ....

是什么让您认为在页面刷新后,树将保持展开/收缩状态?您是否有指向该功能的链接?