gpt4 book ai didi

道场 1.7 : BorderContainer and ContentPanes not working inside of a custom widget template

转载 作者:行者123 更新时间:2023-12-04 16:55:19 27 4
gpt4 key购买 nike

这类似于 question已经在这里,但我使用的是 Dojo 1.7。因此,我无法在自定义小部件模板中使用 BorderContainer 和 ContentPanes。它让我发疯。我尝试添加另一篇文章中建议的mixin,但没有用。

所以我有两个例子。第一个是声明性地使用 dojo 的单个页面,它工作正常。第二个示例是完全相同的页面,但我使用了一个小部件来嵌入模板。它呈现小部件,但它们都粘在右上角。相同的页面,相同的样式。但是,当我调整浏览器窗口的大小时,页面就会成形。仍然有一些缺失,但它更好

  • screenshot here for first example using dojo declaratively
  • screenshot here for second example using a widget
  • screenshot here for second example after resizing the browserwindow .仍然与第一个示例不同,但更好。

  • 非常感谢

    这是第一个例子,有效
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Demo: Application Controller</title>
    <link rel="stylesheet" href="/js/tag/widgets/BorderWidget/css/demo.css" media="screen">
    <link rel="stylesheet" href="/js/tag/widgets/BorderWidget/css/style.css" media="screen">
    <link rel="stylesheet" href="/js/dijit/themes/claro/claro.css" media="screen">

    <!-- Configure Dojo -->
    <script type="text/javascript">
    var djConfig = {
    isDebug : true,
    parseOnLoad : true
    };
    </script>
    <script type="text/javascript" src="/js/dojo/dojo.js"></script>
    <script>
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.TabContainer");
    dojo.require("dijit.layout.ContentPane");
    </script>
    </head>
    <body class="claro">
    <div style="height:100%">
    <div id="appLayout" class="demoLayout" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: 'headline'">
    <div class="centerPanel" id="tabs" data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region: 'center', tabPosition: 'bottom'">
    <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: 'About'">
    <h2>Flickr keyword photo search</h2>
    <p>
    Each search creates a new tab with the results as thumbnails
    </p>
    <p>
    Click on any thumbnail to view the larger image
    </p>
    </div>
    </div>
    <div class="edgePanel" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'top'">
    <div class="searchInputColumn">
    <div class="searchInputColumnInner">
    <input id="searchTerms" placeholder="search terms">
    </div>
    </div>
    <div class="searchButtonColumn">
    <button id="searchBtn">
    Search
    </button>
    </div>
    </div>
    </div>
    </div>
    </body>
    </html>

    这是使用小部件 的第二个示例
    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Demo: Application Controller</title>
    <link rel="stylesheet" href="/js/tag/widgets/BorderWidget/css/demo.css" media="screen">
    <link rel="stylesheet" href="/js/tag/widgets/BorderWidget/css/style.css" media="screen">
    <link rel="stylesheet" href="/js/dijit/themes/claro/claro.css" media="screen">

    <!-- Configure Dojo -->
    <script type="text/javascript">
    var djConfig = {
    isDebug : true,
    parseOnLoad : true,
    paths : {
    'tag' : '../tag/widgets/BorderWidget'
    }
    };
    </script>
    <script type="text/javascript" src="/js/dojo/dojo.js"></script>
    <script>
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.TabContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require('tag.Widget');

    dojo.ready(function() {
    new tag.Widget().startup();
    });
    </script>
    </head>
    <body class="claro">

    </body>
    </html>

    这是小部件代码
    define('tag/Widget', 
    [
    'dojo',
    'dijit/_Widget',
    'dijit/_TemplatedMixin',
    'dijit/_WidgetsInTemplateMixin',
    'dijit/layout/BorderContainer',
    'dijit/layout/TabContainer',
    'dijit/layout/ContentPane'
    ],
    function(d) {
    //The widget contructor will be returned
    return d.declare('tag.Widget',
    [
    dijit._Widget,
    dijit._TemplatedMixin,
    dijit._WidgetsInTemplateMixin
    ],
    {
    templateString : d.cache("tag", "templates/template.html"),

    postCreate : function() {
    this.inherited(arguments);
    var domNode = this.domNode;
    },

    startup : function(args) {
    this.inherited(arguments);
    this.placeAt(dojo.doc.body);
    }


    });
    });

    这是小部件的模板
    <div style="height:100%">
    <div id="appLayout" class="demoLayout" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: 'headline'">
    <div class="centerPanel" id="tabs" data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region: 'center', tabPosition: 'bottom'">
    <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: 'About'">
    <h2>Flickr keyword photo search</h2>
    <p>
    Each search creates a new tab with the results as thumbnails
    </p>
    <p>
    Click on any thumbnail to view the larger image
    </p>
    </div>
    </div>
    <div class="edgePanel" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'top'">
    <div class="searchInputColumn">
    <div class="searchInputColumnInner">
    <input id="searchTerms" placeholder="search terms">
    </div>
    </div>
    <div class="searchButtonColumn">
    <button id="searchBtn">
    Search
    </button>
    </div>
    </div>
    </div>
    </div>

    最佳答案

    您可能需要在自己的 startup() 中显式调用 BorderContainer 和 ContentPane 布局小部件上的启动。方法。此外,您可能希望始终拥有 this.inherited(arguments)如果您要覆盖和继承方法,则在任何小部件生命周期方法中。

    startup : function(args) {
    this.inherited(arguments);
    //console.log('asdasd')
    dojo.empty("body");
    this.placeAt('body');

    this.subContainerWidget.startup();
    //I think the border container will automatically call startup on its children
    //(the content panes), but you may also need to call startup on them.
    }

    另外,正如@missingno 提到的,您可能不想清空 <body>并在小部件启动期间替换它,作为一般的可重用性。

    关于道场 1.7 : BorderContainer and ContentPanes not working inside of a custom widget template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7915364/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com