以编程方式定义时,dojo datagrid autoheight 不起作用

dojo datagrid autoheight not working when programmatically defined

以下代码构建 3 个数据网格,2 个通过标记,1 个通过代码。

当您按下 "autoheight!" 按钮时,只有标记数据网格会调整大小。

我不明白为什么代码数据网格不起作用。据我所知,正在初始化相同的属性。

谢谢

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://js.arcgis.com/3.13/dijit/themes    /claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.13/dojox/grid/resources/claroGrid.css"> 
<script>dojoConfig = {parseOnLoad: true}</script>
<script src="http://js.arcgis.com/3.13/"></script>  
<script>require(["dojo/parser", "dijit/layout/TabContainer", "dijit/layout/ContentPane"]);</script>     
<meta charset="UTF-8">
<title>alubia</title>

<script type="text/javascript"> 
    var test_store;

    var layout = [
        {name:"id", field:"id", width: '165px', noresize: 'true'},
        {name:"data", field:"data", width: '125px', noresize: 'true'}           
    ];

    function loadData(gridId, divId) {                                      
    require(['dojo/data/ItemFileWriteStore', 'dojox/grid/DataGrid'], function(ItemFileWriteStore, DataGrid) {           
        var mi_data = { 
            items : [],
            identifier:"id"
        };                                  

        for (var i = 0; i < 22; i++) {
            mi_data.items.push({id: ""+i, data:"111 ! "+ i});           
        }       

        test_store  = new ItemFileWriteStore({data: mi_data});          

        if (divId != null) {        
            var grid = new DataGrid({
                id : gridId,
                store : test_store,
                structure : layout,
                rowSelector : '0px',
                autoHeight : false                  
            });

            grid.placeAt(divId);    
            grid.startup();
        }
    });         
    }   

    function fitHeight(gridId) {        
        var grid = dijit.byId(gridId);          
        grid.set('autoHeight', true);
        grid.set('autoWidth', false);
        grid.update();          
    }           

    loadData("grid", null);
    loadData("grid2", "grid2Div");
    loadData("grid3", null);
</script>
</head>

<body class="claro" style="font-family:sans-serif; font-size:12px;">
<button onclick="fitHeight('grid'); fitHeight('grid2'); fitHeight('grid3');">autoheight!</button>&nbsp;           

<div id="grid2Div" style="height: 7em;" ></div>
<div id="grid" style="height: 7em;"  data-dojo-id="grid" dojoType="dojox.grid.DataGrid" autoHeight="false" store="test_store" structure="layout" ></div>    
<div id="grid3" style="height: 7em;"  data-dojo-id="grid3" dojoType="dojox.grid.DataGrid" autoHeight="false" store="test_store" structure="layout" ></div>
</body>
</html>

同样,dojo 是一个糟糕的工具。转到数据表(jquery 插件)。太阳又出来了。