我已经在两页中将dijit css用于dijit / horizontalSlider,滑块已在第一页中加载,但在第二页中却变得空白。 dojoz / data / DataGrid也可以在第一页中正确加载,但是在第二页中将变为空白。
更新:
我在home.html(父页面)中有两个按钮,分别调用Django模板grid.html和move.html。这是grid.html源代码
<!DOCTYPE html>
<html >
<head>
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'pmda_app/dojo/../dijit/themes/claro/claro.css' %}">
<style>
@import "{% static 'pmda_app/dojox/grid/enhanced/resources/claro/EnhancedGrid.css' %}";
@import "{% static 'pmda_app/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css' %}"
<script src="{% static 'pmda_app/dojo/dojo.js' %}"></script>
<script>dojoConfig = {parseOnLoad: true}</script>
<script>
dojo.require("dojox.grid.EnhancedGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.enhanced.plugins.Pagination");
dojo.ready(function(){
/*set up data store*/
var data = {
identifier: 'id',
items: []
};
var data_list = [
{ col1: "normal", col2: false, col3: 'But are not followed by two hexadecimal', col4: 29.91},
{ col1: "important", col2: false, col3: 'Because a % sign always indicates', col4: 9.33},
{ col1: "important", col2: false, col3: 'Signs can be selectively', col4: 19.34}
];
var rows = 60;
for(var i=0, l=data_list.length; i<rows; i++){
data.items.push(dojo.mixin({ id: i+1 }, data_list[i%l]));
}
var store = new dojo.data.ItemFileWriteStore({data: data});
/*set up layout*/
var layout = [[
{'name': 'Column 1', 'field': 'id'},
{'name': 'Column 2', 'field': 'col2'},
{'name': 'Column 3', 'field': 'col3', 'width': '230px'},
{'name': 'Column 4', 'field': 'col4', 'width': '230px'}
]];
/*create a new grid:*/
var grid = new dojox.grid.EnhancedGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px',
}},
document.createElement('div')
);
/*append the new grid to the div*/
dojo.byId("gridDiv").appendChild(grid.domNode);
/*Call startup() to render the grid*/
grid.startup();
});
</script>
</head>
<body class="claro">
<div id="gridDiv"></div>
</body>
</html>
这是move.html
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
{% load staticfiles %}
<title>Scaling, scrolling, and panning.</title>
<link rel="stylesheet" href="{% static 'pmda_app/dijit/tests/css/dijitTests.css' %}">
<link rel="stylesheet" href="{% static 'pmda_app/dojo/../dijit/themes/claro/claro.css' %}">
<script type="text/javascript" src="{% static 'pmda_app/dojo/dojo.js' %}" data-dojo-config="isDebug: true, parseOnLoad: true"></script>
<script>dojoConfig = {parseOnLoad: true}</script>
<script type="text/javascript">
dojo.require("dijit.form.HorizontalSlider");
dojo.require("dijit.form.HorizontalRule");
dojo.require("dijit.form.HorizontalRuleLabels");
dojo.require("dijit.form.Button");
dojo.require("dojo.parser"); // scan page for widgets
dojo.require("dojox.charting.Chart");
dojo.require("dojox.charting.axis2d.Default");
dojo.require("dojox.charting.plot2d.Areas");
dojo.require("dojox.charting.plot2d.Lines");
dojo.require("dojox.charting.action2d.MouseZoomAndPan");
dojo.require("dojox.charting.plot2d.Grid");
dojo.require("dojox.charting.action2d.Tooltip");
dojo.require("dojox.charting.themes.PlotKit.orange");
makeObjects = function(){
var data = [4,8,2,1,6,4,8,8,2,1,6,4,9,0,2,8,9,3,4,1,2,1,6,9,1,0,8,2,4,6,1,6,4,8,2,1,6,4,8,2,1,6,4,8,2,1,6,4,8,2,1,6,4,8,2,1,6,4,8,2,1];
var dates = [2013-11-19,2013-11-20,2013-11-21,2013-11-22,2013-11-25];
chart = new dojox.charting.Chart("test");
chart.setTheme(dojox.charting.themes.PlotKit.orange);
chart.addAxis("x", {
labels: dojo.map(dates, function(value, index){
return {value: index + 1, text: value}; }), minorTicks:false, stroke: "green"
})
.addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", minorTicks:false, stroke: "green", min: 0})
.addSeries("UsersGraph", data,{stroke: {color: "blue", width: 1}}, {fill: "green"});
chart.addPlot("default", {type: dojox.charting.plot2d.Lines, gap: 5});
chart.addPlot("grid", {type: dojox.charting.plot2d.Grid, hMinorLines: true});
new dojox.charting.action2d.Tooltip(chart, "default");
chart.render();
};
dojo.addOnLoad(makeObjects);
</script>
</head>
<body class="tundra">
<div id="test" style="width: 500px; height: 300px; margin: 30px auto 0px auto;"> </div>
<table>
<tr><td align="center" class="pad">ZOOM X(<span id="scaleXValue">1</span>)</td></tr>
<tr><td>
<div id="scaleXSlider" data-dojo-type="dijit/form/HorizontalSlider" class="clearfix" value="1" minimum="1" maximum="5" discreteValues="6" showButtons="false" style="width: 500px;">
<div data-dojo-type="dijit/form/HorizontalRule" container="bottomDecoration" count="5" style="height:5px;"></div>
<div data-dojo-type="dijit/form/HorizontalRuleLabels" container="bottomDecoration" minimum="1" maximum="5" count="5" constraints="{pattern: '##'}" style="height:1.2em;font-size:75%;color:gray;"></div>
</div>
</td></tr>
<tr><td align="center" class="pad">PAN X (<span id="offsetXValue">0</span>)</td></tr>
<tr><td>
<div id="offsetXSlider" dojoType="dijit.form.HorizontalSlider"
value="1" minimum="0" maximum="1000" discreteValues="1001" showButtons="false"
style="width: 500px;">
</div>
</td></tr>
</table>
</body>
</html>
首先,我单击了grid.html并正确显示了数据,然后单击move.html以获取带有水平滑块的图表,图表运行正常,但没有滑块。
如果我第一次单击move.html可以正常工作(也可以获取图表和滑块)
最佳答案
从DOJO and DIJIT can not parse same ID twice?:
Dojo跟踪由指定ID创建的对象/小部件。如果您在具有相同ID的对象上再次运行解析器,则dojo会尝试创建第二个实例,但是已经存在一个实例,因此它应该在js控制台中引发错误。
在再次解析同一页面之前,请销毁创建的窗口小部件/对象ID。在这里,我已将“小部件”声明为全局变量,因此,如果有任何小部件ID,则在解析之前将其销毁。
if(widgets){
widgets.forEach(function(widget) {
widget.destroyRecursive();
});
}
widgets = dojo.parser.parse();
对我有用。
关于javascript - 在两页中使用了dijit css,但是仅在第一页中工作,第二页中获得空白页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21721041/