当我动态地将小部件注入页面时。控制台将打印如下错误:
====================================== [对象错误]
Error parsing in _ContentSetter#Setter_dijit_TitlePane_0_pane_0[object Error] Error undefined running custom onLoad code: This deferred has already been resolved
==========================================
我用IE8,Chrome(10.0.648.205),FireFox进行测试? 3.6.16使用dojo1.6,这个bug只发生在IE8中。
以下是我的测试jsp文件:
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>test ie</title>
<style type="text/css">
@import "../dojo16/dijit/themes/claro/claro.css";
@import "../dojo16/dojo/resources/dojo.css"
@import "../dojo16/dojox/grid/resources/Grid.css";
@import "../dojo16/dojox/grid/resources/claroGrid.css";
</style>
<script type="text/javascript" src="../dojo16/dojo/dojo.js"
djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.TitlePane");
dojo.require("dijit.Dialog");
dojo.require("dojox.data.HtmlStore");
dojo.require("dojox.grid.DataGrid");
dojo.addOnLoad(function() {
var reportDiv = dojo.byId("report");
reportDiv.innerHTML = "<H1>Network Statistics Report</H1><table style='display:none' id='W3_TAB_STAGEN_source_table'>"
+ "<thead><tr><th>name</th><th>value</th></tr></thead>"
+ "<tbody<tr><td>Report Name</td><td>Whole Network View</td></tr></tbody>"
+ "</table><div dataId='W3_TAB_STAGEN_source_table' jsId='W3_TAB_STAGEN_store' dojoType='dojox.data.HtmlStore'></div>"
+ "<script type='text/javascript'>"
+ "var W3_TAB_STAGEN_layout = [["
+ " {"
+ " field : 'name', "
+ " name : 'Name', "
+ " width : '50%', "
+ " headerStyles : 'text-align: center' "
+ " },"
+ " {"
+ " field : 'value',"
+ " name : 'Value',"
+ " width : '50%', "
+ " headerStyles : 'text-align: center' "
+ " }"
+ " ]] ; "
+ " </scr" + "ipt>"
+ " <div style='margin: 5px; width: 50%' title='General Information' dojoType='dijit.TitlePane'>"
+ "<table rowCount='1' query='{}' structure='W3_TAB_STAGEN_layout' store='W3_TAB_STAGEN_store' columnReordering='true' autoHeight='true' dojoType='dojox.grid.DataGrid' class='grid' id='W3_TAB_STAGEN'></table>"
+ "</div>";
var scriptStr = dojo.query("script", reportDiv)[0].innerHTML;
console.log(scriptStr);
dojo.eval(scriptStr);
dojo.parser.parse(reportDiv);
});
</script>
</head>
<body class="claro">
<!-- menu -->
<table style="width: 100%">
<tbody>
<tr>
<td style="width: 100%;">
<div id="menubar"></div>
</tr>
</td>
</tbody>
</table>
<BR>
<div id="report" style="width: 100%; height: 100%">
</div>
</body>
</html>
有人可以给我任何提示如何解决这个问题。
最诚挚的问候 莱恩
答案 0 :(得分:1)
你可能有充分的理由按照你的方式去做(好吧......好吧),但我不明白为什么你把W3_TAB_STAGEN_layout
放在HTML / Javascript字符串里?
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.TitlePane");
dojo.require("dijit.Dialog");
dojo.require("dojox.data.HtmlStore");
dojo.require("dojox.grid.DataGrid");
var W3_TAB_STAGEN_layout = [[
{
field : 'name',
name : 'Name',
width : '50%',
headerStyles : 'text-align: center'
},
{
field : 'value',
name : 'Value',
width : '50%',
headerStyles : 'text-align: center'
}
]];
dojo.addOnLoad(function() {
var reportDiv = dojo.byId("report");
reportDiv.innerHTML = "<H1>Network Statistics Report</H1><table style='display:none' id='W3_TAB_STAGEN_source_table'>"
+ "<thead><tr><th>name</th><th>value</th></tr></thead>"
+ "<tbody<tr><td>Report Name</td><td>Whole Network View</td></tr></tbody>"
+ "</table><div dataId='W3_TAB_STAGEN_source_table' jsId='W3_TAB_STAGEN_store' dojoType='dojox.data.HtmlStore'></div>"
+ "<div style='margin: 5px; width: 50%' title='General Information' dojoType='dijit.TitlePane'>"
+ "<table rowCount='1' query='{}' structure='W3_TAB_STAGEN_layout' store='W3_TAB_STAGEN_store' columnReordering='true' autoHeight='true' dojoType='dojox.grid.DataGrid' class='grid' id='W3_TAB_STAGEN'></table>"
+ "</div>";
/*
var scriptStr = dojo.query("script", reportDiv)[0].innerHTML;
console.log(scriptStr);
dojo.eval(scriptStr);
*/
dojo.parser.parse(reportDiv);
});
</script>
这解决了IE8上的问题。我不知道具体是什么导致了这个问题,但我猜你的HTML上的IE浏览器&gt; Javascript-&gt; HTML-&gt; Javascript安排出于某种原因..因为我曾经同意IE,它就是。呃..有点乱; - )