dijit.layout.ContentPane 中的标准方法/事件在不同情况下的调用

前一篇帖子讨论了Dijit 传入参数处理机制,这儿就Dijit中最常用的一个组件dijit.layout.ContentPane,讨论一下dijit标准方法和事件的调用。

dijit.layout.ContentPane[1]包含有一系列的标准方法和事件,又有诸多参数可以设置不同的值来对这些方法/事件的调用施加影响,导致对它的使用看起来非常的纷繁复杂。这儿通过firebug的console输出,尝试查看一下不同情况下,到底dijit.layout.ContentPane的各方法/事件的调用顺序是什么样的。

 

下面定义了一个继承自dijit.layout.ContentPane的自定义dijit组件。在后面,会一一列举不同的实例化方式和配置,及其在相应情景下,各方法/事件的调用情况。时间有限,这儿没有对结果进行分析,只是单纯列出来了。

dojo.declare("Test", [ dijit.layout.ContentPane ], {

	preamble: function(){
		console.log("preamble");
		this.inherited(arguments);
	},
	
	constructor: function(){
		console.log("constructor");
	},

	postMixInProperties: function(){
		console.log("postMixInProperties");
		this.inherited(arguments);
	},

	buildRendering: function(){
		console.log("buildRendering");
		this.inherited(arguments);
	},
	
	postCreate: function(){
		console.log("postCreate");
		this.inherited(arguments);
	},
	
	startup: function(){
		console.log("startup");
		this.inherited(arguments);
	},
	
	cancel: function(){
		console.log("cancel");
		this.inherited(arguments);
	},
	
	destroy: function(){
		console.log("destroy");
		this.inherited(arguments);
	},
	
	destroyRecursive: function(){
		console.log("destroyRecursive");
		this.inherited(arguments);
	},
	
	destroyRendering: function(){
		console.log("destroyRendering");
		this.inherited(arguments);
	},
	
	refresh: function(){
		console.log("refresh");
		this.inherited(arguments);
	},
	
	uninitialize: function(){
		console.log("uninitialize");
		this.inherited(arguments);
	},
	
	onClose: function(){
		console.log("onClose");
		this.inherited(arguments);
	},
	
	onDownloadEnd: function(){
		console.log("onDownloadEnd");
		this.inherited(arguments);
	},
	
	onDownloadStart: function(){
		console.log("onDownloadStart");
		this.inherited(arguments);
	},
	
	onHide: function(){
		console.log("onHide");
		this.inherited(arguments);
	},
	
	onLoad: function(){
		console.log("onLoad");
		this.inherited(arguments);
	},
	
	onShow: function(){
		console.log("onShow");
		this.inherited(arguments);
	},
	
	onUnload: function(){
		console.log("onUnload");
		this.inherited(arguments);
	}
});

注意,除了constructor,别的方法都需要调用this.inherited(arguments)。

 

1. 声明式,不设href

<div dojoType="Test" title="Space">This is a customized content pane.</div>

(1)加载Test所在页面:

preamble
constructor
postMixInProperties
buildRendering
postCreate
startup
onShow

2. 声明式,在html tag中设置href

<div dojoType="Test" title="Space" href=”/simple.do”>This is a customized content pane.</div>

(1)加载Test所在页面:

preamble
constructor
postMixInProperties
buildRendering
cancel
postCreate
startup
refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

3. 声明式,在Test constructor中设置href

<div dojoType="Test" title="Space">This is a customized content pane.</div>

constructor: function(){
	console.log("constructor");
	this.set("href", "/simple.do");
}

(1)加载Test所在页面:

preamble
constructor
cancel
postMixInProperties
buildRendering
cancel
postCreate
startup
refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

4. 编程式,不设href

dojo.ready(function(){
	var test = new Test({}, dojo.byId("container"));
	test.startup();
});

(1)加载Test所在页面:

preamble
constructor
postMixInProperties
buildRendering
postCreate
startup
onShow

(2)调用Test refresh()

refresh
cancel
onDownloadStart
onUnload
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://localhost:8080/js/dojo-1.5.0/dojo/dojo.js.uncompressed.js :: anonymous :: line 10474" data: no]
注意,这儿没有设置href,refresh时就会出错。

 

5. 编程式,在new时设置href

dojo.ready(function(){
	var test = new Test({
        href: “/simple.do”
}, dojo.byId("container"));
	test.startup();
});

(1)加载Test所在页面:

preamble
constructor
postMixInProperties
buildRendering
cancel
postCreate
startup
refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

(2)调用Test refresh()

refresh
cancel
onDownloadStart
onUnload
onLoad
onDownloadEnd

(3)设置一个新的href

cancel
onDownloadStart
onUnload
onLoad
onDownloadEnd

(4)调用Test destroy()

destroy
uninitialize
cancel
destroyRendering


(5)调用Test destroyRecursive()

destroyRecursive
onUnload
destroy
uninitialize
cancel
destroyRendering


6. 编程式,在Test constructor中设置href

dojo.ready(function(){
	var test = new Test({}, dojo.byId("container"));
	test.startup();
});

constructor: function(){
	console.log("constructor");
	this.set("href", "/simple.do");
}

(1)加载Test所在页面:

preamble
constructor
cancel
postMixInProperties
buildRendering
cancel
postCreate
startup
refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

(2)调用Test refresh()

refresh
cancel
onDownloadStart
onUnload
onLoad
onDownloadEnd

(3)设置一个新的href

cancel
onDownloadStart
onUnload
onLoad
onDownloadEnd

(4)调用Test destroy()

destroy
uninitialize
cancel
destroyRendering


(5)调用Test destroyRecursive()

destroyRecursive
onUnload
destroy
uninitialize
cancel
destroyRendering


7. 声明式,Test实例挂在TabContainer下,并在一开始隐藏。在Test constructor中设置href,preload为false

<div id="container" dojoType="dijit.layout.TabContainer" style="width:1000px;height:400px;">
	<div dojoType="dijit.layout.ContentPane" title ="22222" >2222</div>
	<div dojoType="Test" title="Space" preload="false">
		This is a customized content pane.
	</div>
</div>

constructor: function(){
	console.log("constructor");
	this.set("href", "/simple.do");
}

(1)加载Test所在页面:

preamble
constructor
cancel
postMixInProperties
buildRendering
cancel
postCreate
startup

(2)选中Test实例所在的tab

refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

8. 声明式,Test实例挂在TabContainer下,并在一开始隐藏。在Test constructor中设置href,preload为true

<div id="container" dojoType="dijit.layout.TabContainer" style="width:1000px;height:400px;">
	<div dojoType="dijit.layout.ContentPane" title ="22222" >2222</div>
	<div dojoType="Test" title="Space" preload="true">
		This is a customized content pane.
	</div>
</div>

constructor: function(){
	console.log("constructor");
	this.set("href", "/simple.do");
}

(1)加载Test所在页面:

preamble
constructor
cancel
postMixInProperties
buildRendering
cancel
postCreate
startup
refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

(2)选中Test实例所在的tab

onShow

9. 声明式,Test实例挂在TabContainer下,并在一开始隐藏。在html tag中设置href,preload为false

<div id="container" dojoType="dijit.layout.TabContainer" style="width:1000px;height:400px;">
	<div dojoType="dijit.layout.ContentPane" title ="22222" >2222</div>
	<div dojoType="Test" title="Space" preload="false" href="/simple.do" >
		This is a customized content pane.
	</div>
</div>

(1)加载Test所在页面:

preamble
constructor
postMixInProperties
buildRendering
cancel
postCreate
startup

(2)选中Test实例所在的tab

refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

10. 声明式,Test实例挂在TabContainer下,并在一开始隐藏。在html tag中设置href,preload为true

<div id="container" dojoType="dijit.layout.TabContainer" style="width:1000px;height:400px;">
	<div dojoType="dijit.layout.ContentPane" title ="22222" >2222</div>
	<div dojoType="Test" title="Space" preload="true" href="/simple.do" >
		This is a customized content pane.
	</div>
</div>

(1)加载Test所在页面:

preamble
constructor
postMixInProperties
buildRendering
cancel
postCreate
startup
refresh
cancel
onDownloadStart
onShow
onLoad
onDownloadEnd

(2)选中Test实例所在的tab

onShow


(3)调用tabcontainer removeChild()

  

(4)关闭Test实例所在的tab (点击tab上的X,或者调用tab container closeChild())

destroyRecursive
onUnload
destroy
uninitialize
cancel
destroyRendering

这儿需要将Test的onClose注释掉。不然关闭tab功能将不起作用。


(5)调用tabcontainer destroyDescendants()

onShow
destroyRecursive
onUnload
destroy
uninitialize
cancel
destroyRendering


参考文献:

[1] Dojo Toolkit API, http://dojotoolkit.org/api/


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>通过属性查询地图服务的信息</title> <link rel="stylesheet" href="https://js.arcgis.com/3.39/esri/css/esri.css"> <!-- <link rel="stylesheet" type="text/css" href="./css/esri.css" /> --> <link rel="stylesheet" href="https://js.arcgis.com/3.40/esri/themes/calcite/dijit/calcite.css"> <script src="https://js.arcgis.com/3.41/"></script> <script> require(["esri/map", //载地图组件 "dojo/dom", "dojo/on", "esri/InfoTemplate", "esri/graphic", "esri/geometry/Point",//载点对象组件 "esri/symbols/SimpleMarkerSymbol", "esri/geometry/Extent",//载范围组件 "esri/layers/FeatureLayer", //载FeatureLayer地图组件 // "esri/dijit/FeatureTable", "esri/layers/WebTiledLayer", //载切片地图组件 "esri/layers/ArcGISDynamicMapServiceLayer",//载动态地图组件 "esri/symbols/SimpleFillSymbol", "esri/renderers/UniqueValueRenderer", "esri/tasks/query", "esri/tasks/QueryTask", "esri/Color", "dojo/domReady!" ], function (Map, dom, on, InfoTemplate, Graphic, Point, SimpleMarkerSymbol,Extent, FeatureLayer, WebTiledLayer, ArcGISDynamicMapServiceLayer, SimpleFillSymbol, UniqueValueRenderer, Query, QueryTask, Color, GeoJsonLayer) { //初始化地图容器 // map = new Map("map", { logo: false, slider: false }, {zoom: 8}); map = new Map("map", { center: [109.33789 , 29.57985], basemap: "satellite", zoom: 10, sliderStyle: "small", logo: false }); // 创建底图 var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"); map.addLayer(basemap,0); // 创建动态图层 var dynamicLayer = new ArcGISDynamicMapServiceLayer("http://116.62.63.94:6080/arcgis/rest/services/sanhuxiangtest/MapServer"); map.addLayer(dynamicLayer,99); }) </script> </head> <body class="tundra"> <div id="map" style="width:900px; height:580px; border:1px solid #000;"></div> 类别名称:<input class="nm" type="text"> </body> </html>
最新发布
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值