• Dojo中的模块插件


      除了通常的模块,AMD加载器(这里就是指dojo.js)的另一个功能点就是一种新的被称为插件的模块,功能是用于扩展加载器的功能,跟其他普通模块一样以同样的方式被加载,但在模块标志符的后面会添加一个特殊的字符“!”,用来表明这是一个插件请求,“!”后的数据会直接传递给插件进行处理。几个最重要的插件:dojo/textdojo/i18ndojo/hasdojo/domReady

    1) dojo/text

    dojo/text是用于从文件(比如HTML模板)中加载字符串,这些字符串会把缓存起来,这样,后面再次调用加载同样的文件的时候 就不会再需要额外的网络请求了。在对web程序做build的时候,构建工具会将dojo/text加载的字符串直接替换到js代码中。比如,为一个模板widget导入模板,你需要这样定义你的模块。

     1 //in "my/widget/NavBar.js"
     2 define([
     3     'dojo/_base/declare',
     4     'dijit/_WidgetBase',
     5     'dijit/_TemplatedMixin',
     6     'dojo/text!./templates/NavBar.html'
     7 ],function(declare,_WidgetBase,_TemplatedMixin,template){
     8     return declare([_WidgetBase,_TemplatedMixin],{
     9         //加载"my/widget/templates/NavBar.html"中的文本内容
    10         templateString : template
    11     });
    12 });

    2) dojo/i18n

    dojo/i18n会根据浏览器的用户区域设置加载不同的语言资源包

    
    
     1 //in "my/widget/Dialog.js"
     2 define([
     3     "dojo/_base/declare",
     4     "dijit/Dialog",
     5     "dijit/i18n!./nls/common"
     6 ],function(declare,Dialog,i18n){
     7     return declare(Dialog,{
     8         title:i18n.dialogTitle
     9     });
    10 });

    3) dojo/has

     Dojo的加载器包含了一套符合has.js定义的用于检测环境信息的API的实现代码,jojo/has插件就是用于有条件地为那些需要的模块完成这一功能。

     1 // in "my/events.js"
     2 define([
     3     "dojo/dom" 4     "dojo/has!dom-addeventlistener?./events/w3c:./events/ie"
     5 ],function(dom, events){ 
     6 // events is "my/events/w3c" if the 
     7 //"dom-addeventlistener" test was true, "my/events/ie" otherwise 
     8     events.addEvent(dom.byId("foo"),"click",function(){
     9         console.log("Foo clicked!");
    10     });
    11  });

    4) dojo/onReady

    Dojo/domReady dojo/ready的替代品。这个表示只有当DOM初始化后才会执行模块。我们使用这个插件的目的只是为了延迟回调函数的执行,不需要使用返回值的模块或者插件应该天灾需要的模块列表的尾部,因此这个回调函数不需要定义任何参数,尽管,数据没有传递给domReady插件,但为了表名这是个插件,“!”必须写上。

    1 // in "my/app.js" 
    2 define([
    3 "dojo/dom",
    4 "dojo/domReady!"
    5 ],function(dom){ 
    6     // This function does not execute until the DOM is ready 
    7     dom.byId("someElement"); 
    8 });  
  • 相关阅读:
    Sharepoint List Attachments in a Webpart : The Solution
    MOSS 文档库操作类
    许多实用的js 正则表达式
    SharePoint 调查列表的自定义错误页面
    排序算法——插入排序
    用vs2010创建带有AssociationForm的工作流
    does not have element "configuration/configSections/sectionGroup[@name='SharePoint']" or it is invalid
    CSharp数据库使用SqlCommand进行增,删,改,查询操作
    去掉视图选择栏
    IList与Xml互相转换
  • 原文地址:https://www.cnblogs.com/sere/p/4819238.html
Copyright © 2020-2023  润新知