Dojo学习笔记八:Dojo布局――面板

Dojo提供了多种基本的布局方式,使用这些布局,可以有层次,有意义的组织控件,使得 web 界面获得更好的用户体验。

Dojo提供布局小部件分为三类:面板、对齐方式容器和堆叠容器。

1、dijit/layout/ConentPane

ContentPane,顾名思义,就是用于放置若干内容的面板,是各种布局的基本元素。ContentPane 的功能类似于 iFrame。除此之外 ContentPane 还可以与其他 Layout 控件互相嵌套。

ContentPane声明法示例

<!DOCTYPEhtml>
<html>
<head>
<Metacharset="UTF-8">
<styletype="text/css">
body{width:100%;height:100%;}
</style>
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true">
</script>
<scripttype="text/javascript">
dojo.require("dijit.layout.ContentPane");
</script>
<title>ContentPane学习</title>
</head>
<body>
<divdojoType="dijit.layout.ContentPane"id="myFirstContentPane"
href="TestContentPane.html">
</div>
</body>
</html>

ContentPane程序生成法示例

<!DOCTYPEhtml>
<html>
<head>
<Metacharset="UTF-8">
<styletype="text/css">
body{width:100%;height:100%;}
</style>
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true">
</script>
<scripttype="text/javascript">
/*1.7以前版本http://dojotoolkit.org/reference-guide/1.10/dojo/domready.html#dojo-domready
dojo.require("dijit.layout.ContentPane");
dojo.addOnLoad(function(){
varmyFirstContentPane=newdijit.layout.ContentPane({
id:"myFirstContentPane",href:"testcontentPane.html"
},dojo.byId("myFirstContentPane"));
myFirstContentPane.startup();
});
*/
require(["dijit/layout/ContentPane","dojo/domready!"],function(ContentPane){
varmyFirstContentPane=newContentPane({
id:"myFirstContentPane",dojo.byId("myFirstContentPane"));
myFirstContentPane.startup();
});
</script>
<title>ContentPane学习</title>
</head>
<body>
<divid="myFirstContentPane">
</div>
</body>
</html>

输出结果:

wKioL1Q_hAqCVU8oAABfAizvf4Q400.jpg

说明:

(1)在这个例子中,ContentPane 完全实现了iFrame 的功能,但是有些区别,在代码中会把testcontentPane.html页面中的<title>测试</title>属性带过来。

(2)在使用程序生成法时,不要忘记startup()


1.1 Content属性:String,DomNode,NodeList

指ContentPane中显示内容。如果没有定义 href 属性,ContentPane 组件内将显示 content 内容。否则将显示 href 页面内容。content 可以是 String,DomNode 和 NodeList 三种类型。

<!DOCTYPEhtml>
<html>
<head>
<Metacharset="UTF-8">
<styletype="text/css">
body{width:100%;height:100%;}
</style>
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true">
</script>
<scripttype="text/javascript">
require(["dijit/layout/ContentPane",function(ContentPane){
//创建一个DomNode,table元素
varmyDomNode=document.createElement("table");
//Table的第一行是”Hello,DojoWorld!”
varmyTD1=document.createElement("td");
myTD1.innerHTML="Hello,DojoWorld!";
varmyTR1=document.createElement("tr");
myTR1.appendChild(myTD1);
myDomNode.appendChild(myTR1);
//Table的第二行是”Hello,ContentPaneWorld!”
varmyTD2=document.createElement("td");
myTD2.innerHTML="Hello,ContentPaneWorld!";
varmyTR2=document.createElement("tr");
myTR2.appendChild(myTD2);
myDomNode.appendChild(myTR2);
myDomNode.border=1;
//将创建的DomNode赋给content属性
varmyFirstContentPane=newContentPane({
id:"myFirstContentPane",//href:"TestContentPane.html"
content:myDomNode
},dojo.byId("myFirstContentPane"));
myFirstContentPane.startup();
});
</script>
<title>ContentPane学习</title>
</head>
<body>
<divid="myFirstContentPane">
</div>
</body>
</html>

输出结果:

Hello,Dojo World!
Hello,ContentPane World!


1.2 title属性:String

title属性定义了ContentPane的标题。这个标题只有当 ContentPane 作为 TabContainer/ StackContainer 等 Layout 控件的子控件时,才可以看到。此时该属性显示于该 Tab 页的标题处。

<divclass="centerPanel"data-dojo-type="dijit.layout.TabContainer"data-dojo-props="region:'center',tabPosition:'bottom'">
<divdata-dojo-type="dijit.layout.ContentPane"title="Group1">
<h4>Group1Content</h4>
<p>Group1测试</p>
</div>
<divdata-dojo-type="dijit.layout.ContentPane"title="GroupTwo">
<h4>Group2Content</h4>
<p>Group2测试</p>
</div>
<divdata-dojo-type="dijit.layout.ContentPane"title="GroupThree">
<h4>Group3Content</h4>
<p>Group3测试</p>
</div>
</div>

输出结果:

wKioL1Q_iAyyqtOvAABbUTfDryc071.jpg

1.3 loadingMessage/errorMessage属性:String

当ContentPane内容/页面加载中,或出现错误时,ContentPane 将会显示内容。该信息可以在loading.js文件中更改。

myContentPane.attr("loadingMessage","StillLoading…");


1.4placeAt(reference,position)函数

这是一个常用的方法,dojo控件都实现了这个方法。运用这个方法可以自由地放置控件的位置。该方法有两个参数:reference,和 position。可以接受的 reference 参数类型有:String,DomNode 和 _Widget。其中 String 为引用 Dom 节点 (DomNode),或者 dojo 控件 (_Widget) 的 id。而被position参数传入的dojo控件,必须是实现了addChild方法的类型,可接受的 position 参数类型有 Int和String。传入的 String 参数必须是”first”,”last”,”before”,”after”中的一个

Parameter Type Description
reference String | DomNode | _Widget

Widget,DOMNode,or id of widget or DOMNode

position String | Int

Optional.

If reference is a widget (or id of widget),and that widget has an ".addChild" method,it will be called passing this widget instance into that method,supplying the optional position index passed. In this case position (if specified) should be an integer.

If reference is a DOMNode (or id matching a DOMNode but not a widget),the position argument can be a numeric index or a string "first","last","before",or "after",same as dojo/dom-construct::place().

myContentPane.placeAt("OuterContentPane","first");

该例子中,myContentPane 将被嵌套放入 OuterContentPane 的第一个位置。


1.5 attr(name,value)函数

attr是常用的dojo控件通用方法,用于为 dojo 控件的属性赋值。如:_Widget.attr(“value”,3) 相当于 _Widget.setValue(3)。在新的版本中,许多用于修改属性方法被不推荐了,如 setValue,setHref 等,均由 attr(“value”,value),attr(“href”,href) 方法取代。

Parameter Type Description
name String | Object

The property to get or set. If an object is passed here and not a string,its keys are used as names of attributes to be set and the value of the object as values to set in the widget.

value Object

Optional.

Optional. If provided,attr() operates as a setter. If omitted,the current value of the named property is returned.

备注:dojox.layout.ContentPane扩展了dijit.layout.ContentPane。


2 dijit/TitlePane

TitlePane本质上仍然是一个ContentPane,不同点是,TitlePane自带了Title 的显示标题栏中包括一按钮与一标题,通过按钮可控制显示或隐藏内容。在 TitlePane 中,title 属性定义了显示标题

<!DOCTYPEHTML>
<htmllang="en">
<head>
<Metacharset="UTF-8">
<linkrel="stylesheet"href="dijit/themes/soria/soria.css">
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true"></script>
<scripttype="text/javascript">
require(["dijit/TitlePane","dojo/parser"]);
</script>
<title>TitlePane学习</title>
</head>
<bodyclass="soria">
<divid="myTitlePane"style="border:solidblack1px;">
<pid="last">HelloTitlePane!</p>
<divdata-dojo-type="dijit/TitlePane"data-dojo-props="title:'Pane#1'">
I'mpane#1
</div>
<divdata-dojo-type="dijit/TitlePane"data-dojo-props="title:'Pane#2'">
I'mpane#2
</div>
<divdata-dojo-type="dijit/TitlePane"data-dojo-props="title:'Pane#3'">
I'mpane#3
</div>
</div>
</body>
</html>

输出结果:

wKiom1Q_m8DBIesoAAEzK-wF2gM191.jpg

2.1 duration属性:number

收起和打开 TitlePane,是一个动画过程,duration 定义了该动画持续的时间,单位是毫秒。

myTP.attr("duration",1000);


3 dojox/layout/FloatingPane

FloatingPane是可以随意移动的TitlePane,可以模拟Windows窗口效果的浮动面板,可以在页面上随意拖拽该面板,该面板具有最基本的最小化、还原、最大化和关闭按钮等,可以改变大小,可以嵌套内部窗口,可以打开其他页面等。

FloatingPane声明法示例:

<!DOCTYPEHTML>
<htmllang="en">
<head>
<Metacharset="UTF-8">
<linkrel="stylesheet"href="dijit/themes/soria/soria.css">
<linkrel="stylesheet"type="text/css"href="dojox/layout/resources/FloatingPane.css">
<linkrel="stylesheet"type="text/css"href="dojox/layout/resources/ResizeHandle.css">
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true"></script>
<scripttype="text/javascript">
require(["dojox/layout/FloatingPane","dojo/parser"]);
</script>
<title>FloatingPane学习</title>
</head>
<bodyclass="soria">
<divdojoType="dojox.layout.FloatingPane"id="myFloatingPane"
title="FloatingWorld"closable="true"
resizable="true"dockable="true"
style="position:absolute;top:0;left:0;width:150px;height:150px;">
TheContentoftheFloatingWorld!
</div>
</body>
</html>

FloatingPane程序生成法示例:

<!DOCTYPEHTML>
<html>
<head>
<Metacharset="UTF-8">
<linkrel="stylesheet"href="dijit/themes/soria/soria.css">
<linkrel="stylesheet"type="text/css"href="dojox/layout/resources/FloatingPane.css">
<linkrel="stylesheet"type="text/css"href="dojox/layout/resources/ResizeHandle.css">
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true"></script>
<scripttype="text/javascript">
require(["dojox/layout/FloatingPane","dojo/parser",function(FloatingPane){
varmyFP=newFloatingPane({
id:"myFloatingPane",content:"TheContentoftheFloatingWorld!",resizable:true,dockable:true,title:"FloatingWorld",closable:true,style:{position:"absolute",top:0,left:0,width:"150px",height:"150px"}
},dojo.byId("myFloatingPane")
);
myFP.startup();
});
</script>
<title>FloatingPane学习</title>
</head>
<bodyclass="soria">
<divid="myFloatingPane">
TheContentoftheFloatingWorld!
</div>
</body>
</html>

运行结果:

wKioL1Q_nUWAXOwxAACCGsxzeb4390.jpg

上面创建方法得到的FloatingPane显示如下图所示,用户可以自由地在它的外层容器中移动位置。

说明:

(1)必须引用 FloatingPane.css;

(2)如果需要具备改变容器大小 (resize) 功能,需引用 ResizeHandle.css;

(3)Dojo建议在动态创建小部件结束后,调用startup()。


3.1 closable属性:boolean

closable 属性定义了该面板是否可以被关闭


3.2 resizable属性:boolean

属性定义了FloatingPane是否可以在运行时改变大小。当 resizable 为 true 并引用了 ResizeHandle.css时,用户可以通过拖动控制点来改变面板的大小。


3.3 dockable属性:boolean

属性定义了FloatingPane是否可以被最小化到页面的最下方。与 TitlePane 可以收起面板不同的是,FloatingPane 可以将面板最小化到页面的最下方,如同 Windows 的工具栏。当dockable为true 时,用户可以通过点击面板标题位置向下的三角来最小化面板。


3.4 sytle属性:object

属性定义了面板的位置。其中position定义是绝对位置还是相对位置,top和left定义了面板左上角的位置,width和height定义了面板的大小。但当面板被拖动或改变大小时,该值不会跟着变化。


4dojox/layout/ExpandoPane

与ContentPane基本类似,不过可以展开或折叠,不可以包含其他布局小部件。

<!DOCTYPEHTML>
<html>
<head>
<Metacharset="UTF-8">
<linkrel="stylesheet"href="dijit/themes/soria/soria.css">
<linkrel="stylesheet"type="text/css"href="dojox/layout/resources/ExpandoPane.css">
<styletype="text/css">
html,body{
width:100%;
height:100%;
margin:0;
}
#borderContainer{
width:100%;
height:100%;
}
</style>
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true"></script>
<scripttype="text/javascript">
require(["dijit/layout/ContentPane","dijit/layout/BorderContainer","dojox/layout/ExpandoPane","dojo/domready!"]);
</script>
<title>ExpandoPane学习</title>
</head>
<bodyclass="soria">
<divdata-dojo-type="dijit.layout.BorderContainer"data-dojo-props="design:'sidebar',gutters:true,liveSplitters:true"id="borderContainer">
<divdata-dojo-type="dojox.layout.ExpandoPane"title="LeftExpando"data-dojo-props="title:'LeftExpando',maxWidth:225,splitter:true,region:'leading'"style="width:225px;">
Hi.I'mtheExpandoPane
</div>
<divdata-dojo-type="dijit.layout.ContentPane"data-dojo-props="splitter:true,region:'center'">Hi,I'mcenter</div>
</div>
</body>
</html>

输出结果:

wKioL1Q_o3PRamRyAAEM2BnNHgM505.jpg


5dojox/layout/ScrollPane

ScrollPane是可以滚动的面板。当面板内容超出了面板显示范围时,使用 ScrollPane 可以让内容滚动起来。

<!DOCTYPEHTML>
<html>
<head>
<Metacharset="UTF-8">
<linkrel="stylesheet"href="dijit/themes/soria/soria.css">
<linkrel="stylesheet"type="text/css"href="dojox/layout/resources/ScrollPane.css">
<scripttype="text/javascript"src="dojo/dojo.js"djConfig="parSEOnLoad:true"></script>
<scripttype="text/javascript">
require(["dijit/TitlePane","dojox/layout/ScrollPane","dojo/domready!"]);
</script>
<title>ScrollPane学习</title>
</head>
<bodyclass="soria">
<divstyle="float:left;padding-right:12px;">
<divdojoType="dojox.layout.ScrollPane"style="width:150px;height:300px;"orientation="vertical"id="vert">
<tableid="tableinvert">
<tr>
<td>
<divdojoType="dijit.TitlePane"title="1"sytle="width:100%;height:100%;">titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="2"sytle="width:100%;height:100%;">
titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="3"sytle="width:100%;height:100%;">titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="4"sytle="width:100%;height:100%;">
titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="5"sytle="width:100%;height:100%;">
titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="6"sytle="width:100%;height:100%;">
titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="7"sytle="width:100%;height:100%;">
titlePanecontent
</div>
</td>
</tr>
<tr>
<td>
<divdojoType="dijit.TitlePane"title="8"sytle="width:100%;height:100%;">
titlePanecontent
</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>

结果:

wKioL1Q_pqzwSTMoAAC4PZAvUUs173.jpg

说明:必须引用dojox/layout/resources/ScrollPane.css,否则在面板内容滚动时,不会显示滚动滑块。


5.1 orientation属性:String

定义了ScrollPane的滚动方向,有verticalhorizontal两种选择。需要注意的是,滚动的方向必须出现内容显示不下的情况,否则SrollPane的显示效果和ContentPane没有区别。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


我有一个网格,可以根据更大的树结构编辑小块数据.为了更容易知道用户保存了什么,我希望当用户第一次看到网格时,网格处于不可编辑状态.当用户准备好后,他们可以单击编辑按钮,这将使网格的某些部分可编辑.然后,有一个保存或取消按钮可以保存更改或还原.在大多数情况下它是有效的.但
我即将开始开发一款教育性的视频游戏.我已经决定以一种我可以轻松打包为Web,Mobiles和可能的Standalone版本的方式来实现这一目标.我不想使用Flash.因此,我确信(无论如何我会听取建议)使用JavaScript和SVG.我正在对这个问题进行大量研究,但我很难把各个部分放在一起.我知道Raphae
我正在使用带有Grails2.3.9的Dojo1.9.DojoNumberTextBox小部件–我在表单中使用–将固定格式(JavaScript基本格式)的实数值(例如:12.56)设置为HTML表单输入字段(但根据浏览器区域设置显示/编辑它们,所以用户总是看到格式正确的数字).另一方面,Grails期望输入字段根据浏览器
1.引言鉴于个人需求的转变,本系列将记录自学arcgisapiforjavaScript的学习历程,本篇将从最开始的arcgisapiforjavaScript部署开始,个人声明:博文不在传道受业解惑,旨在方便日后复习查阅。由于是自学,文章中可能会出现一些纰漏,请留言指出,不必留有情面哦!2.下载ArcGISforDe
我正在阅读使用dojo’sdeclare进行类创建的语法.描述令人困惑:Thedeclarefunctionisdefinedinthedojo/_base/declaremodule.declareacceptsthreearguments:className,superClass,andproperties.ClassNameTheclassNameargumentrepresentsthenameofthec
我的团队由更多的java人员和JavaScript经验丰富组成.我知道这个问题曾多次被问到,但为了弄清楚我的事实,我需要澄清一些事情,因为我在客户端技术方面的经验非常有限.我们决定使用GWT而不是纯JavaScript框架构建我们的解决方案(假设有更多的Java经验).这些是支持我的决定的事实.>
路由dojo/framework/srcouting/README.mdcommitb682b06ace25eea86d190e56dd81042565b35ed1Dojo应用程序的路由路由FeaturesRoute配置路径参数RouterHistoryManagersHashHistoryStateHistoryMemoryHistoryOutletEventRouterContextInjectionOutl
请原谅我的无知,因为我对jquery并不熟悉.是否有dojo.connect()的等价物?我找到了这个解决方案:http:/hink-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/但是没有断开功能!你知道jquery的其他解决方案吗?有jquery.connect但这个插件在我的测试中不起作用.
与java类一样,在dojo里也可以定义constructor 构造函数,在创建一个实例时可以对需要的属性进行初始化。//定义一个类mqsy_yjvar mqsy_yj=declare(null,{     //thedefaultusername    username: "yanjun",          //theconstructor   
我一直在寻找一些最佳实践,并想知道Dojo是否具有框架特定的最佳实践,还是最好只使用通用的Javascript标准?特别是我主要是寻找一些功能和类评论的指导方针?解决方法:对于初学者来说,这是项目的风格指南:DojoStyleGuide
我有’05/17/2010’的价值我想通过使用dojo.date.locale将其作为“2010年5月17日”.我尝试过使用dojo.date.locale.parse,如下所示:x='05/17/2010'varx=dojo.date.locale.parse(x,{datePattern:"MM/dd/yyyy",selector:"date"});alert(x)这并没有给我所需的日期
我正在尝试创建一个包含函数的dojo类,这些函数又调用此类中的其他函数,如下所示:dojo.provide("my.drawing");dojo.declare("my.drawing",null,{constructor:function(/*Object*/args){dojo.safeMixin(this,args);this.container=args[0];
我知道你可以使用jQuery.noConflict为jQuery做这件事.有没有办法与Dojo做类似的事情?解决方法:我相信你可以.有关在页面上运行多个版本的Dojo,请参阅thispage.它很繁琐,但似乎是你正在寻找的东西.一般来说,Dojo和jQuery都非常小心,不会破坏彼此或其他任何人的变量名.
我有一个EnhancedGrid,用户经常使用复杂的过滤器.有没有办法允许用户保存或标记过滤器,以便将来可以轻松地重新应用它?我知道我可以通过编程方式设置过滤器,但我无法预测用户想要的过滤器.谢谢!编辑:自己做了一些进展…使用grid.getFilter()返回过滤器的JSON表示,然后使用json.strin
我有这个代码:dojo.declare("City",null,{constructor:function(cityid,cityinfo){}});dojo.declare("TPolyline",GPolyline,{constructor:function(points,color){},initialize:function(map){});应该是什
我遇到的问题是我的所有javascript错误似乎来自dojo.xd.js或子模块.我正在使用chrome调试器和许多dijit功能,如dijit.declaration和dojo.parser.这有点烦人,因为它很难找到简单的错误或滑倒.我希望我可以添加一个选项,允许我的调试器在我的非dojo代码中显示选项会发生的位置.我是
我正在使用DojoToolkit数字/解析函数来处理格式化和使用ICU模式语法解析字符串.有没有人知道有可能采取任意ICU模式字符串并以某种方式使用Dojo(或其他)库将其分解为它的部分(例如,对于数字模式,它可以被分解为小数位数,数千个分组等…).我希望这样做,而不需要让我的代码密切了
我有两个看似相关的问题,访问在不同的地方定义的javascript函数.我遇到的第一个问题是调用我在firgbug或safari控制台中定义的函数.我定义了一个名为getRed的函数,如下所示:functiongetRed(row,col){//dosomethingstuffandreturntheredvalueasa
我想添加一个在Ajax调用中指定的外部样式表.我已经找到了一种方法来使用jQuery(参见下面的示例),但是我需要使该方法适应dojoJavaScript框架.JQuery示例$('head').append('<linkrel="stylesheet"type="text/css"href="lightbox_stylesheet.css">');谢谢.解决方法:一旦你
我正在尝试使用dojo.connect将onMouseDown事件连接到图像,如:dojo.connect(dojo.byId("workpic"),"onMouseDown",workpicDown);functionworkpicDown(){alert("mousedown");}类似的代码几行后,我将onMouse*事件连接到dojo.body确实完全正常工作.但是当我点击图像时