直接觀看文章

[dojo] save dijit.layout.TabContainer selected tab

七月 31, 2011

用繼承的方式果然好搞很多, 直接攔截事件開始處理…
又可以重複使用

	dojo.declare("dijit.MyTabContainer" , [ dijit.layout.TabContainer ] ,
	{
		postCreate : function() {
			var childId = dojo.cookie(this.id);
			var tabContainerId = this.id;
			if (childId !== undefined) {
				// use dojo.addOnLoad to avoid tab content not ready.
				dojo.addOnLoad(function() {
					var selectedChild = dijit.byId(childId);
					if (selectedChild !== undefined) {
						dijit.byId(tabContainerId).selectChild(selectedChild);
					}
				});
			}
			this.inherited(arguments);
		},                                                                                                                                                                                                                                                                           

		selectChild : function(selectedTab) {
			// save selected tab id
			if (selectedTab !== undefined) {
				dojo.cookie(this.id, selectedTab.id , { expires : 365 });
			}
			this.inherited(arguments);
		}
	});
尚無迴響

發表迴響

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

連結到 %s

Follow

Get every new post delivered to your Inbox.