0

在我的 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>

Cookies 被激活。我希望这发生在客户端。用 chrome、firefox 和 IE 试了一下。

4

1 回答 1

0

缺少树的 ID。使用 id 它可以工作:

var tree = new Tree({
    id: "yourtree",
    model: myModel,
    ....
于 2013-05-03T08:09:32.260 回答