dojo.tree没有节点持久性

时间:2013-05-02 09:55:51

标签: javascript dojo

在我的ASP.NET项目中,我尝试使用一些dojo UI元素。我的第一次尝试是在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>

Cookie已激活。我希望这只发生在客户端。尝试使用chrome,firefox和IE。

1 个答案:

答案 0 :(得分:0)

树的ID丢失了。使用id它可以工作:

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