Home > Web Front-end > JS Tutorial > body text

Ajax dominates the world Dojo integration chapter_dojo

WBOY
Release: 2016-05-16 19:16:17
Original
1227 people have browsed it

With more and more Ajax applications, various Ajax Library (Prototype), Ajax Framework (DWR), and Ajax Toolkit (Dojo, YUI) are becoming increasingly abundant. Is there any way to combine these? Similar to Spring's approach, of course I can't create an IoC microkernel to "glue" various Ajax together, but there should be no problem integrating these Ajax reusable components, so as to avoid reinventing the wheel. You can also use the strengths and avoid weaknesses of various Ajax to form a relatively comprehensive Ajax solution. It also increases the flexibility for developers to choose their own familiar Ajax components.​
At present, our company has formed a complete set of products based on Ajax, which encapsulates its own Ajax front-end and back-end communication mechanisms and provides reusable client components. I tried to integrate our products with Dojo Toolkit. The following is my approach. The Dojo ComboBox Widget is integrated, which is actually an Auto Completion component, similar to Google Suggest.​
Start with the test class test_ComboBox.html provided by Dojo, add a debugger for tracking and debugging, and clarify the loading process of Dojo Widget.​
After tracking and debugging, I have a general understanding of Dojo's Widget: first, load the currently required JavaScript file, and then parse the entire html page. There are three ways to use widgets on the page: one is to add some attributes that Dojo can parse on the HTML element, such as
The control part html to be loaded below:
dataUrl="cmdComboboxSearch"
dataProviderClass = "dojo.widget.incrementalDoradoComboBoxDataProvider"
style="width: 200px;"
name="sample2"
autocomplete="false"
                                               
In this way, our integration work is completed, and by the way, there is also the directory structure of the files:
Webapp
|--adapter (stores all js files used for integration)
|------dojo
|---------widget
|-----------DoradoComboBox.js
|--dojo (all js files of dojo)
|------src
|------dojo.js
|--js (js file of our own component library)
|--WEB-INF
Conclusion
After the expansion, many problems were discovered:
1. Since the two integrated sets of things will add some of their own things to Object.prototype, Array.prototype, and Function.prototype, it is very easy to cause naming conflicts. I have already encountered this problem.​ <script></script>2. Since both will use some global functions, variables, etc., there will be potential conflicts, but we have not encountered them yet.​ <script> <br> dojo.require("dojo.widget.ComboBox"); <br> // 注意这里有一个定位的问题,查找路径必须加"..", <br> // 因为dojo在查找DoradoComboBox.js的时候会从"/dojo"而不是"/"目录开始查找 <br> // 最终使用xmlhttp加载的路径是/dojo/../adapter/dojo/widget/DoradoComboBox.js <br> dojo.setModulePrefix("adapter.dojo.widget","../adapter/dojo/widget"); <br> dojo.require("adapter.dojo.widget.DoradoComboBox"); <br></script>3. Multiple sets of js libraries need to be loaded at the same time. Is the pressure on the client too high? Is the performance acceptable? No testing is available yet.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template