我有一个带有 3 个内容窗格的选项卡容器,仅在调整浏览器大小时才加载,但在实际页面加载期间不加载。模板文件 TContainer.html 如下
<div style="width:100%;height:100%" >
<div dojoType="dijit.layout.TabContainer" data-dojo-attach-point="tab" open="true" tabPosition="top" style="width:100%; margin:5px;font-weight:bold; overflow-y:visible;" tabStrip="true" doLayout="false">
<!-- content panes: title is tab name, make this tab selected -->
<div dojoType="dijit.layout.ContentPane" style="width:100%;height:100%;" data-dojo-props="title:'Tab1',selected:'true'">
</div>
<!-- content panes: title is tab name, no special features here -->
<div dojoType="dijit.layout.ContentPane" style="width:100%;height:100%;" data-dojo-props="title:'Tab2'">
</div>
<!-- content panes: title is tab name, make this tab closable -->
<div dojoType="dijit.layout.ContentPane" style="width:100%;height:100%;" data-dojo-props="title:'Tab3'">
</div>
</div>
小部件的关联 TContainer.js 文件如下
define([
"dojo/_base/declare",
"dojo/_base/fx",
"dojo/_base/lang",
"dojo/dom-style",
"dojo/mouse",
"dojo/on",
"dojo/query",
"dijit/layout/TabContainer",
"dijit/layout/ContentPane",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./templates/TabContainer.html"
], function(declare, baseFx, lang, domStyle, mouse, on,query,TabContainer,ContentPane,_WidgetBase, _TemplatedMixin,_WidgetsInTemplateMixin,template){ return declare( [_WidgetBase, _TemplatedMixin,_WidgetsInTemplateMixin], {
templateString: template,
c1:"content1",
c2:"content2",
c3:"content3",
// A class to be applied to the root node in our template
baseClass: "tabWidget",
constructor: function (args) {
// Allow pages variable to be set at runtime
declare.safeMixin(this, args);
},
resize: function () {
this.tab.resize(arguments);
this.inherited(arguments);
},
postCreate: function(){
// Run any parent postCreate processes - can be done at any point
this.inherited(arguments);
},
});
});
我使用以下代码以编程方式创建小部件
var Tab = new TContainer({"c1" : "content1",
"c2":"content2",
"c3":"content3 answers"
});
//dnode is a div node
Tab.placeAt(dnode);
Tab.startup();
Tab.resize();