简体   繁体   English

包括Spring Roo的dojo / dom库

[英]Including dojo/dom library to Spring Roo

How is it possible to include and use the dojo/dom library in Spring roo. Spring Roo中如何包含和使用dojo / dom库。

This: 这个:

 <script type="text/javascript">
                      dojo.require('dojo/dom');
                      dojo.ready(function remAttr(){
                          dojo.removeAttr('theId', 'value');
                        }
                     );
</script>

results in: 结果是:

"NetworkError: 404 Introuvable - http://localhost:8131/suivitrc/resources/dojo/dom.js"
dom.js
Could not load 'dojo/dom'; last tried '../dojo/dom.js'

Can anyone please help? 谁能帮忙吗?

I think the version of dojo in roo is currently less than 1.7. 我认为roo中的dojo版本目前小于1.7。 This means you can remove the following line from your code because the remoteAttr function is part of dojo.js: 这意味着您可以从代码中删除以下行,因为remoteAttr函数是dojo.js的一部分:

dojo.require('dojo/dom');

see here: http://dojotoolkit.org/reference-guide/1.7/dojo/removeAttr.html 参见此处: http : //dojotoolkit.org/reference-guide/1.7/dojo/removeAttr.html

The namespace => to module path is retreived by replacing periods (.), in short - you need to replace the slash with a dot. 简而言之,通过替换句点(。)可以获取命名空间=>到模块路径的信息-简而言之,您需要用点代替斜杠。 Your require should be 您的要求应该是

  dojo.require('dojo.dom'); // blocking call? djConfig.async must be false

Since the error is in regards to the dojo.require specified path, this means your dojo.js is found and loaded (dojo.require is not undefined) - and baseUrl is not of concern to dojo modules. 由于错误是关于dojo.require指定的路径的,所以这意味着您的dojo.js已找到并已加载(dojo.require并非未定义)-并且doU模块不关心baseUrl。

The thing is, youre using the legacy loader to pull in an AMD module, in 1.7+ the require statement has a different look to it. 事实是,您使用旧版加载器插入AMD模块,在1.7+中,require语句的外观与此不同。

  // AMD loader form is
  function callbackFunctionOnComplete(dojoDom) { }
  require([ "dojo/dom" ], callbackFunctionOnComplete); // non-blocking

So, how dojo.require works is following, assume that the parameter we pass as string is called 'module; 因此,遵循dojo.require工作原理,假设我们以字符串形式传递的参数称为'module;

dojo.require = function(module) {
   var parts = module.split('.');

1 - get toplevel namespace (global) 1-获取顶级名称空间(全局)

   var packageName = parts.shift(); // first part is the package name

2 - get the filename (minus .js) 2-获取文件名(减去.js)

   var id = parts.pop(); // the last bit

3 - translate everything in between to a path (relative to packagelocation) 3-将介于两者之间的所有内容转换为路径(相对于packagelocation)

   var mid = parts.join("/");

4 - lookup package (from toplevel) location 4-查找包(从顶层)位置

   var fullpath = // in pseudo
       foreach dojoconfig.packages 
         iff obj.name == packageName 
            set to obj.location

5 append the rest and start downloading module 5追加其余部分并开始下载模块

   fullpath += mid + id + '.js'
   transport.get(..... fullpath .....)

You need to configure dojo with dojo config. 您需要使用dojo config配置dojo。 I prefer the form explained here: 我更喜欢这里解释的形式:

http://dojotoolkit.org/reference-guide/1.7/dojo/_base/config.html#explicitly-creating-a-dojoconfig-object-before-including-the-dojo-core . http://dojotoolkit.org/reference-guide/1.7/dojo/_base/config.html#explicitly-creating-a-dojoconfig-object-before-includes-the-dojo-core

And you need to tell dojo where to find its stuff. 而且您需要告诉dojo在哪里可以找到它的东西。 An example: 一个例子:

 var dojoConfig =
  {
     baseUrl : "/yourApp/js",  // defines the js folder in your webapp
     tlmSiblingOfDojo: false,
     async: true,
     parseOnLoad:true,
     packages: [
        { name: "app", location: "app"}, // where it is in the js folder

        { name: "dojo", location: "lib/dojo" }, // where it is in the js folder
        { name: "dijit", location: "lib/dijit" },
        { name: "dojox", location: "lib/dojox" }
     ]
  };

Also the require form you are using is deprecated. 另外,您使用的需求表也已弃用。 See http://livedocs.dojotoolkit.org/dojo/require 参见http://livedocs.dojotoolkit.org/dojo/require

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM