6

我有以下问题:

以编程方式创建 dijit.Dialog 和 dojox.grid.DataGrid(链接到全局变量数据存储 (dojo.store.Memory) )不会显示 Dialog 的内容,而 Dialog 大小保持在最小值。

DataGrids 存储已正确填充,Firebug 在对话框中显示网格。

data = new dojo.data.ObjectStore(
  { objectStore: new dojo.store.Memory({data:[]}) });

data.put({id:0,name:'Franklin'});

showDialog = function(){
  var dlg = dijit.byId('myDlg');
  if(dlg){
    dlg.show();
  }
  else{
    var cp = new dijit.layout.ContentPane({style:"width:500;height:500;"});
    var grid = new dojox.grid.DataGrid({
      store : data,
      structure : [
        {field:'id',name:'ID',width:'50px'},
        {field:'name',name:'Name',width:'400px'}]
    },cp);

    dlg = new dijit.Dialog({
      id:'myDlg',
      title:'Names',
      content:cp.domNode
    });

    grid.startup();
    dlg.show();
  }
);

也许我以错误的顺序添加了一些东西?

此外,我不知道我使用 domNode 属性组合/附加 dojo 小部件的方式是否是正确的做事方式。

我不知道我使用的 ContentPane 是否需要将 Grid 放置在 Dialog 内。到目前为止,这两种变体都不起作用。

最后,我不确定 Dialog 是否以及在何处需要静态测量才能正确调整大小。以我的经验,对话框本身不需要静态宽度或高度,但到目前为止,我还没有向对话框添加像 Grid 这样的动态组件的经验——它可能会在启动时改变它的大小。

4

2 回答 2

2

您不需要先显示对话框,这超出了对话框的目的。您需要创建网格,将 domNode 附加到对话框,然后显示对话框。这适用于我的所有代码。最好的

于 2011-09-28T16:27:16.680 回答
2

这是我上述问题的一种可能的解决方案。在这种情况下,对话框需要就位并可见。只有在那之后,才创建了 Grid,将其放置在 Dialog 中并启动。

对话框和网格都需要明确的尺寸。如果对话框有一些其他内容,它可能不需要额外的宽度信息。

var myDialog = dijit.byId('myDialog');
if(!myDialog){
    myDialog = new dijit.Dialog({
        id:'myDialog',
        title:'test dialog',
        style:'width:600px;height:600px;'
    });
}
myDialog.show();

var myMemoryStore = new dojo.store.Memory(
    {data:[
        {'id':'0','lastname':'Frank'},
        {'id':'1','lastname':'Herbert'}]});
var myObjectStore = new dojo.data.ObjectStore({objectStore:myMemoryStore });

var myStructure = [
    {field:'id',       name:'ID',   width:'20px'},
    {field:'lastname', name:'NAME', width:'200px'}];

var myGrid = dijit.byId('myGrid');
if(!myGrid){
    myGrid= new dojox.grid.DataGrid({
        id:'myGrid',
        store:myObjectStore ,
        structure:myStructure,
        style:'width:400px;height:400px;'
    });
}

dojo.place(myGrid.domNode,myDialog.containerNode,'first');
myGrid.startup();
于 2011-05-18T09:04:40.877 回答