Dojo datagrid parent作为innerHTML元素id

时间:2011-05-21 22:33:03

标签: datagrid dojo innerhtml

请注意,如果“if(true)”未切换为false,则不会呈现任何内容。换句话说,如果传递给数据网格构造函数的父节点是innerHTML元素id,为什么没有渲染。如果是这样的话,有人能告诉我怎么做吗?


    
        
            @import "dojo/dijit/themes/tundra/tundra.css";
            @import "dojo/dojox/grid/resources/Grid.css";
            @import "dojo/resources/dojo.css"
        
        
        
    
    
        dojo.require("dijit._Widget");
        dojo.require("dijit._Templated");
        dojo.require("dojox.grid.DataGrid");
        dojo.require("dojo.data.ItemFileReadStore");

        dojo.addOnLoad(function()
        {
            dojo.require('dojo.parser');
        });

        dojo.ready(function()
        {
            dojo.parser.parse();

            var top = "root";
            if (true) // ';
                dojo.parser.parse();
                top = "first";
            }

            // Create the data grid parameters.
            var layout =
            [
                { name: 'Name', field: 'name', width: '100px' },
                { name: 'Color', field: 'color', width: '100px' }
            ];

            var dataStore =
            {
                data :
                {
                    items :
                    [
                        { name : 'John Doe', color: 'green' },
                        { name : 'Jane Doe', color: 'red' }
                    ]
                }
            };

            var grid = new dojox.grid.DataGrid
            (
                {
                    store: new dojo.data.ItemFileReadStore(dataStore),
                    clientSort: true,
                    structure: layout
                },
                dojo.byId(top)
            );

            grid.startup();
        });

    
     
        
    

1 个答案:

答案 0 :(得分:0)

HTML:

<div id="top"></div>

的javascript:

dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require('dojo.parser');
dojo.ready(function()
{
    // Create the data grid parameters.
    var layout =
    [
        { name: 'Name', field: 'name', width: '100px' },
        { name: 'Color', field: 'color', width: '100px' }
    ];
    var dataStore = {
        data :
        {items :[
        { name : 'John Doe', color: 'green' },
        { name : 'Jane Doe', color: 'red' }
        ],
        label:'name',
        identifier:'color'
        }
    };

    var grid = new dojox.grid.DataGrid
    (
        {
        store: new dojo.data.ItemFileReadStore(dataStore),
        clientSort: true,
        structure: layout
        },
        "top" // this id should be there in HTML .
    );
});