Dojo风格编码 [英] Dojo style coding

查看:164
本文介绍了Dojo风格编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢dojo风格的编码。习惯了纯粹的javascript然后jQuery风格。搜索并得到一些结果,例如




  • Dojo与闭包编译器一起使用时效果最好。

  • 高级dojo比程序类型更加OO



我有问题




  • dojo.require() - 每当我下载一个dojo的插件,我会收到错误 - 404 NOT FOUND。一半的开发时间用于解决这个问题,获取js文件并将其放置在位置。

  • 是否可以扩展dojo对象,就像jQuery一样扩展根jquery对象使用$ .fn.some函数,内部定义为 jQuery.fn = jQuery.prototype 。在dojo中有类似的东西。

  • 我觉得dojo的文档不如jQuery那么好。

  • 什么是dijit和dojox?当我从Google api库导入dojo.js,然后在dojo中使用插件时,这些dijit和dojox总是一个问题。



需要一些帮助。我将几个插件从jQuery移植到dojo。这些插件在dojo中不可用。



我觉得在使用dojo进行编码时,您必须使用整个库,然后编译它才能获得优化的代码,并将其导出到所需的位置。我在这里吗如果没有,我做错了什么?

解决方案

1)dojo.require通过XHR请求自动下载所需的文件。您不需要手动下载任何东西。如果您使用Google CDN,所有类都应从那里下载,我建议您将完整的软件包下载到您的本地应用程序并从中使用。之后,您可能想要创建一个 Build 。您还应阅读从Dojo开始



2)像jQuery一样增强dojo没有任何意义。 dojo 只是顶级的命名空间,在这里你有很多类,如 dojo.Animation dojo.behavior dojo.Deferred dojo.NodeList 和很多其他班有些是像 dojo.connect() dojo.style()



如果您要创建一个新的课程,请参阅 dojo.declare 。您还可以在 dojo 命名空间或其他命名空间下创建新类。



如果要向 dojo 命名空间添加新功能,只需键入 dojo.new_function = function(){} 像普通的JavaScript一样。但我不会推荐这个。如果升级到以后的Dojo版本,它可能会出现问题。



jQuery和Dojo完全不同。如果您在jQuery中输入类似 $('。data')的内容,则会使用data类获取所有dom节点,并返回一个新对象,该对象包含在code> jQuery class。



在Dojo中,您使用 dojo.query('。data')的效果相同。但它返回一个类型为$ code> dojo.NodeList 的新对象。如果你想添加新的功能到链的能力,你需要扩展dojo.NodeList。



已经存在一些扩展,如 dojo.NodeList- fx 将动画效果添加到 dojo.NodeList 类中。如果您使用 dojo.require()加载该类,则dojo.Nodelist将自动扩展。有关详细信息,请参阅扩展dojo.NodeList



3)文档相当不错,您所要求的所有内容都已经记录在案,我在Dojo主页上提供了一些完整的资源。不同的是,Dojo是一个完整的工具包,包括GUI,布局系统,Widgets,数据抽象和许多其他真正高级的东西。如果你从来没有使用过这样的东西,可能很难从它开始,因为它含有这么多东西。 jQuery不提供任何这样的东西。所以有时候确定比较容易开始。



有关文档资料:





4)Dojo是一个在JavaScript中使用3个命名空间的工具包 dojo dijit dojox dojo 命名空间包含几乎每个人以后使用的东西,如I18N的框架,L10N,模型抽象,如 dojo.data dojo.store 和很多其他的东西。



只需将dojo.js文件加载方式不给你 dojo 提供的一切。



命名空间 dijit 在Dojo中包含大量小部件。 dijit 命名空间中的所有小部件都具有完整的I10N和L10N支持。 dijit 包含对话框,布局系统,窗口小部件,如日历,按钮,选择字段,无线电字段,一个完整的 dijit.Editor下的所见即所得编辑器



另请参阅 Dijit主题编辑器查看Dijit包含的内容。完整的网站包括布局完整基于dijit。



dojox 命名空间包含大量额外的功能,不适合 dijit 或是实验性的。但不是一切都是实验性的。您可以找到 dojox.grid.DataGrid dojox.charting 开始制图高级图表)或像 dojox.gfx 创建使用SVG,Canvas,VRML,Silverlight或Flash的跨浏览器图形。



只需查看超越Dojo的核心即可获得(小)概述什么dijit和dojox包含。


I'm new to dojo style coding. Got used to pure javascript and then jQuery style. Searched through and got some results such as

  • Dojo, when used with closure compiler works best.
  • advanced dojo is more OO than procedural type

I'm having problems with

  • dojo.require() - whenever I download a plugin for dojo, I get the error - 404 NOT FOUND. and half the time for developing goes in fixing this issue, getting the js file and placing it at location.
  • And is it possible to extend the dojo object as in jQuery we extend the root jquery object by using $.fn.somefunction that is internally defined as jQuery.fn = jQuery.prototype. Is there something similar in dojo.
  • And I feel documentation for dojo is not as good as jQuery's.
  • What are dijit and dojox ? When I import dojo.js from Google api library, and then using a plugin in dojo, these dijit and dojox were always a problem.

Need some help. I'm porting few plugins from jQuery to dojo. These plugins are not available in dojo.

I feel that you have to use the entire library when coding using dojo, and then compile it to get the optimized code, and export it to whereever needed. Am I right here? if not, what am I doing wrong?

解决方案

1) dojo.require automatically downloads the needed files through XHR requests. You don't need to download anything manually. If you use the google CDN all classes should download from there, i would recommend to download the full package to your local application and use it from there. Later you probably want to create a Build. You should also read Starting with Dojo

2) Enhancing dojo like jQuery don't makes any sense. dojo is just the top namespace and under it you have a lot of classes like dojo.Animation, dojo.behavior, dojo.Deferred, dojo.NodeList and a lot of other classes. Some are functions like dojo.connect() and dojo.style().

If you want to create a new class look into dojo.declare. You can also create new classes under the dojo "namespace" or other namespaces.

If you want to add a new function to the dojo namespace, you can just type dojo.new_function = function(){} Like normal JavaScript. But i wouldn't recommend that. It can make problems if you upgrade to later Dojo versions.

jQuery and Dojo are completly different. If you type something like $('.data') in jQuery it fetches all dom-nodes with the class "data" and it returns a new object wraped in the jQuery class.

In Dojo you use dojo.query('.data') for the same effect. But it returns a new object of the type dojo.NodeList. If you want to add new functions to the chain ability you need to extend dojo.NodeList.

There already exists some extension like dojo.NodeList-fx that adds the Animation effect to the dojo.NodeList class. If you load the class with dojo.require() your dojo.Nodelist will extend automatically. Look into Extend dojo.NodeList for more information.

3) The documentation is quite good, everything you asked is already documented and i provided some ressources you completly find on the main page from Dojo. The difference is that Dojo is a completly Toolkit, including GUI, layout systems, Widgets, data abstraction and a lot of other really high-level stuff. If you never worked with something like that, it could be hard to start with it because it contains so much. jQuery doesn't provide anything like this. So sometimes it is sure easier to start with it.

For documentation look at:

4) Dojo is a toolkit that uses 3 namespaces in JavaScript dojo, dijit and dojox. The dojo namespace contains things that nearly everybody uses later, like a Framework for I18N, L10N, model abstraction like dojo.data or dojo.store and a lot of other stuff.

Just loading the "dojo.js" file by the way don't give you everything that dojo provides.

The dijit namespace contains a lot of widgets in Dojo. All Widgets in the dijit namespace have full I10N and L10N support. dijit contains Dialog, Layout Systems, Widgets like calendar, buttons, select fields, radio fields, a full WYSIWYG Editor under dijit.Editor.

Also see the Dijit Theme Editor to see what Dijit contains. The complete site including layout is complete based on dijit.

The dojox namespace contains a lot of extra functionality that dont fit in dijit or are experimental. But not everything is experimental. You find things like the dojox.grid.DataGrid or dojox.charting (Start Charting, Advanced Charting) or Systems like dojox.gfx to create cross-browser graphics that uses SVG, Canvas, VRML, Silverlight or Flash.

Just look into Beyond Dojo's Core to get a (small) overview what dijit and dojox contains.

这篇关于Dojo风格编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆