【问题标题】:Dojo.. cannot execute javascript in contentpaneDojo .. 无法在内容窗格中执行 javascript
【发布时间】:2011-04-29 23:41:53
【问题描述】:

我有一个独立的 html 页面,其中包含一个运行良好的 dojo DataGrid。我包括下面的相关代码。


    <script type="text/javascript">
    var readStore, grid;
      var gridLayout = [
      new dojox.grid.cells.RowIndex({ name: "Row #", width: 5, styles: "text-align: left;" }),
      {
        name: "Name",
        field: "name",
        styles: "text-align:right;",
        width:30
      },
      {
        name: "Type",
        field: "type",
        width:20
      }
    ];
   function initGrid()
   {
     readStore=new dojox.data.QueryReadStore({url:"/EG3/orgUnit/getChildren",  requestMethod:"get"});
console.info("readStore initialized");

grid=new dojox.grid.DataGrid({store:readStore,
  id:"grid",
  delayScroll:true,
  structure:gridLayout,
  query:{id:2},
  loadingMessage:"Loading..."
}, document.createElement('div'));

dojo.byId("gridContainer").appendChild(grid.domNode);
grid.startup();
 }
  dojo.addOnLoad(initGrid);
</script>

</HEAD>
<BODY class="claro">
<div id="list" class="list">
  Table goes here
 <div id="gridContainer">
 </div>
</div>

现在,当我尝试将此页面作为内容窗格包含在 TabContainer 中时,就会出现问题。 TabContainer 按原样加载页面标记,并且不会触发包含网格的页面的 onLoad 脚本。

                  <div dojoType="dijit.layout.TabContainer" region="center" tabStrip="true" id="orgUnitTabs">
                <div dojoType="dojox.layout.ContentPane" title="Info" selected="true" id="orgInfo" jsId="orgInfo">

                </div>
                <div dojoType="dojox.layout.ContentPane" href="/EG3/app/orgUnit/orgUnitChildren.gsp" executeScripts="true" parseOnLoad="true" extractContent="true" title="Children" id="children" jsId="children">
                    Children of the selected Org
                    <script type="javascript" event="onLoad">
                     initGrid();
                    </script>
                </div>

关于如何触发子页面的 onLoad 脚本有什么想法吗?

提前致谢。

【问题讨论】:

    标签: datagrid dojo


    【解决方案1】:

    不确定正确的答案是什么,但如果我是你,我会尝试以编程方式而不是声明方式执行所有操作,捕获错误,使用控制台输出查看正在发生的事情并在加载时记录事件。

    【讨论】:

    • 感谢您的回复。我将executeScripts设置为true,但这没有任何区别。不过,我终于得到了一个可行的解决方案。它真正对我有用的唯一方法是将 javascript 包装在另一个内容窗格中的子页面中,并使 scripttype="dojo/method"。
    【解决方案2】:

    你应该检查参数executeScripts是否设置为TRUE,如果你想使用声明式方法,你必须手动解析domNode,详见dojo.parse方法:http://docs.dojocampus.org/dojo/parser

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      相关资源
      最近更新 更多