使用dijit css在两个页面,但仅在第一页工作,在第二页获得空白页 [英] Used dijit css in two pages, but working in first page only, in second page getting blank page

查看:179
本文介绍了使用dijit css在两个页面,但仅在第一页工作,在第二页获得空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dijit / horizo​​ntalSlider中使用了dijit css两页,滑块正在第一页被加载,但在第二页中变为空白。 dojoz / data / DataGrid也正确地加载到第一页,但第二页空白。

I have used dijit css for dijit/horizontalSlider in two pages , slider is getting loaded in first page but in second page getting blank. dojoz/data/DataGrid also loaded correctly in first page, but in second page getting blank.

更新:

我在home.html(父页面)中有两个按钮,并调用django模板grid.html和move.html。这里是grid.html源代码

I have two buttons in home.html(parent page) and calling django templates grid.html and move.html. Here is grid.html source code

    <!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,并在点击移动后正确显示了数据。 html图表与水平滑块,图表正确,但没有滑块在那里。
如果我点击move.html第一次它是wokring罚款(获取图表和滑块也)

First I have clicked on grid.html and it displayed the data correctly, after that clicked on move.html for chart with horizontal sliders, chart came properly but no sliders are there. If I clicked move.html first time it is wokring fine(getting chart and sliders also)

推荐答案

从<一个href =https://stackoverflow.com/a/15889588> DOJO和DIJIT不能两次解析相同的ID :


Dojo跟踪由指定的id创建的对象/小部件。如果您在同一个id的对象上再次运行解析器,dojo会尝试创建一个第二个实例,但是已经有一个实例,所以应该在你的js控制台中抛出一个错误。

Dojo keeps track of the objects / widgets it creates by the specified id. If you run the parser again on an object with the same id, dojo tries to create a second instance, but there is already one, so it should throw an error in your js console.

在再次解析同一页面之前,销毁创建的小部件/对象标识。在这里我已经将小部件声明为全局变量,所以如果有任何小部件ids在解析之前就摧毁它们。

Destroy the created widget/object ids before you parse the same page again. Here I have declared 'widgets' as global variable, so that if any widgets ids are there just destroying them before parsing.

    if(widgets){
        widgets.forEach(function(widget) {
        widget.destroyRecursive();
    });
    }
    widgets =  dojo.parser.parse();

它适用于我。

这篇关于使用dijit css在两个页面,但仅在第一页工作,在第二页获得空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆