|
Three. Summary, Introduction 1. Dojo.io.bind Common Properties or methods: {url:,load:,error:,mimetype:,method:,transport:,formnode:} Load,error can be replaced by handle, in the handle to determine the state, according to different states do different things. Transport specifies what object to transmit, such as XMLHTTP,IFRAMEI/O,SCRIPTSCRIO,ETC, if not specified, the default is XMLHTTP. (1). XMLHttp: Is the default transport object, because of security issues: cannot transfer files, cannot cross another domain request data, File://protocol form is invalid. (2). IFRAMEI/O: Able to transfer files, response type can be Text,html,js/json (3). Scriptscrio: The ability to transfer files, request data across another domain, and provide a number of properties and methods. (4). In addition, dojo can access remote methods through a remote procedure call protocol, and can access another domain using XMLHTTP through an IFRAME proxy.
|
2.widget Package Interesting components: Fisheyelist,button,menu2,checkbox,combobox,datepicker,dropdowndatepicker,tooltip,titlepane,slideshow, ContentPane, Resizehandle,resizabletextarea,tree,accordionpane,etc. You can customize the components or inherit existing components and overload the properties and methods of the parent component, such as: Dojo.widget.defineWidget ("My.mybutton", dojo.widget.html.button,{}), the first parameter is the custom component name, the second parameter is the parent component, and the third parameter {} To overload the parent component's properties or methods, or to define additional properties or methods. Dojo.io.bind () encapsulates the xmlhttprequset creation process, so it is no longer necessary to use Try...catch statement blocks for Cross-browser. Dojo.io.bind () takes a hash table as an argument, including Url:value, Load:value, Error:value, and Mimetype:value. Where the URL is necessary, the rest is optional. The value of load and error is a callback function, which can be used as a parameter to respond to the normal and valid response text, DOM events, and error messages, respectively, in Type,data,evt,error. And mimetype can be text/plain, text/html and flexible text/javascript.
Asynchronous submission of forms using dojo implementations Dojo.io.bind () adds a formnode to the parameter table with a value of document.getElementById (form_id), which should be triggered when the form needs to be submitted (guess, I haven't tried yet).
A way to solve the problem of forward back button to some extent After Dojo's encapsulation, the following section of the program will be executed at the appropriate time:
Backbutton:function () { Something Todo } Forwardbutton:function () { Something Todo }
Dojo.io.bind () can also add a changeurl that can be either true or a string that adds "#时间戳" or a custom identity to the URL.
Other parameters: Method: Used to specify whether it is post or get Content: Added request parameters Postcontent: Request parameters added only at post Sync: Specifies synchronous or asynchronous, default is asynchronous UseCache: Whether to use caching Write your own Dojo extensions
Objective Dojo is a very popular JavaScript framework, and it gives itself a definition on its own wiki, an Open-source DHTML Toolbox written in JavaScript. Dojo is eager to be a "unification" toolbox, not only at the browser level, but also with great ambition. But Dojo brings up some new ideas for JavaScript programming, where it's a good idea to introduce a package mechanism for dynamic loading. Understanding Dojo's package mechanism In fact, dojo only needs some very small load code can be used to load its various packages, the Dojo-ajax download contained in its official site is still relatively large, because it includes some of the most commonly used packages in JS, but many times we don't need so many features, Or on-demand loading is better. Luckily, we can download all of the custom versions of Dojo in the http://download.dojotoolkit.org/address, but the components are all the same. But the size of the dojo.js is very different, so we start with the minimal version. After downloading, you will find that the minimal version contains only 18kb dojo.js, which contains only the loading mechanism, which is very good. That way, we can start writing our own Dojo extensions. Dojo Code structure After the uncompressed directory contains the SRC directory, the src directory is stored in the various components of dojo, we have a new Hello directory here. Create a new name for the __package__.js file, similar to Python, which defines how many classes to import by default when introducing this namespace, and the name of the namespace. Our goal is to do a dojo.hello.Echo extension, so the code in the __package__.js should be like this: The role of Kwcompoundrequire is how many classes you need to load by default when you import the entire Dojo.hello package These definitions are inside this function, where the common represents the default load, which is not fixed Dojo wants to be a "unification" implementation, so considering the non-browser situation, there can be other things, such as Rhino Dojo.kwcompoundrequire ({ Common: [ "Dojo.hello.Echo" ] }); This defines the package, which is written by default | Why, of course, yes, look at your savvy.:-) Dojo.provide ("dojo.hello.*"); we specify the default loaded class echo, so we'll write the Echo class, create a new echo.js in the Hello directory, and the code reads as follows: Class name definition, JavaScript write twist, in fact, is directly defined class name Dojo.provide ("Dojo.hello.Echo");
Class definition section, very familiar code Dojo.hello.Echo = function () { THIS.name = "Dojo.hello.Echo"; This.sayhello = function (greeting) { return greeting; } The extension has been written, very simple, and the next is dropped, index.html as follows. <script language= "javascript" src= "Dojo.js" ></script> <script language= "JavaScript" > Dojo.require ("dojo.hello.*"); var echo = new Dojo.hello.Echo (); document.write (Echo.sayhello ("Hello World")); </script> <body>
</body> More content This example is a very simple introduction to the Dojo package loading mechanism, of course, the class in this package does not refer to other classes, Dojo also allows the dynamic loading of other classes in the code, of course, these are implemented through the XMLHTTP, because it is synchronous mode, So the request of the analogy is more and are not included in the dojo.js when there will be the phenomenon of page pauses, this is still need to pay attention to. Code in the article download:, dojo-hello.tar.gz Some of the Dojo resources: Dojo Official site Dojo Handbook Dojo Wiki
|