Web开发基本概念之Dojo

来源:互联网 发布:数据防泄密系统 编辑:程序博客网 时间:2024/05/21 22:59

Dojo是什么?

关于这个问题,网络上有很多答案和各种解释,本人觉得最还是看看Dojo的官方文档是怎么说的。

Dojo is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, f(m) and Burstlib), which is why we refer to it sometimes as a "unified" toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.

                                     摘自《The Dojo Book,0.4

简单的说,Dojo就是一个基于javascript实现的开源工具包。Dojo开始于20049月,网址是http://www.dojotoolkit.org,由JotSpotAlex Russell所领导。我们知道,辅助开发的工具可以称为框架,库,或者包,那么,称Dojotoolkit(工具包),这是为什么呢?在软件开发中,框架通常定义为可供其他项目(工程)组织和开发的一个定义好的支持结构。明显,我们不能把dojo当成框架来理解,它其实只是框架中的一部份而已。库则被定义为一组相关函数的集合,它们一般不可以独立运行,也许我们该称dojo为库才对呢,事实上,dojo不只是一个库而已。工具包通常服务在GUI开发中,亦即关注GUI开发,Dojo具有的加载机制(Package System) 可以实现动态加载所需模块,而且用户可以编写自己的Dojo扩展模块,有很好的灵活性。

Dojo结构如何?

Dojo is a set of layered libraries. The bottom most layer is the packaging system that enables you to customize the distribution of Dojo for your application. On top of Dojo's package system reside language libraries such as the Dojo event system and the language utilities that greatly improve and simplify the lives of JavaScript developers. Environment-specific libraries are provided in some cases, but in most uses, you'll only need to know that all of Dojo works without incident across every major browser.

The bulk of the Dojo code lives in the application support libraries, which are too numerous to display completely in the diagram. dojo.gfx provides native vector graphics support across the major browser implementations of SVG and VML. dojo.lfx is a lightweight effects library, while dojo.io is "where the ajax lives."

Most of the "action" in Dojo is in the widget toolkit, that contains a template-driven system for constructing widgets, a declarative parser for putting widgets in pages without writing JavaScript, and a set of base components that implement common-case solutions to web interaction problems that HTML+CSS alone cannot solve.

如何使用Dojo?

下载Dojo

可以去Dojo官网http://www.dojotoolkit.org下载,最新的版本是1.3.2,建议初学的同志们先下着老点儿的版本,因为网上的大多资料都是版本比较老的,这东西更新地太快了。

Dojo应用到程序中

1、  标志

    <script type="text/javascript">
       djConfig = { isDebug: false };

</script>

djConfigDojo里的一个全局对象, 其作用就是为Dojo提供各种选项, isDebug是最常用的属性之一, 设置为True以便能够在页面上直接看到调试输出。

2、  引用Dojo核心包

<script type="text/javascript" src="/yourpath/dojo.js" />

这里我要特别说下dojo.js的地址问题,下载了dojo工具包后,可有两种途径引用。第一种,直接将dojo包解压到工程的web应用目录中,而后进行引用。第二种,将dojo包解压到web服务器下,网上某些人说应该解压在服务器的webapp目录下,我试过了,最终会无法引用的,就tomcat而言,只用将dojo解压在ROOT目录下方可,引用方式如下:

<script type="text/javascript" src="../dojotoolkit/dojo/dojo.js">

3、申明包

  <script type="text/javascript">

  dojo.require("dojo.math");

  dojo.require("dojo.io.*");

  dojo.require("dojo.widget.*");

</script>

你就把这些代码当成是javaimport语句或C#中的using语句一样, 如果你不require的话, 而模块本身又没有整合在dojo.js, 是会出现脚本错误的。

原创粉丝点击