【问题标题】:How to link JS file with modules, controls & templates in dotnetnuke?如何将 JS 文件与 dotnetnuke 中的模块、控件和模板链接?
【发布时间】:2013-08-22 07:04:15
【问题描述】:

我是 dotnetnuke 的新手,所以我不知道如何将 js 文件与模块链接,控制 dotnetnuke 中的模板。

谁能帮帮我...

【问题讨论】:

    标签: javascript jquery dotnetnuke


    【解决方案1】:

    如果你想包含 JS 文件,你应该把它们放到你模块中的一个文件夹中(通常是一个 JS 文件夹)

    然后在 Codebehind 中你可以使用下面的语法

    ClientResourceManager.RegisterScript(Parent.Page, "~/Resources/Shared/scripts/knockout.js");
    ClientResourceManager.RegisterScript(Parent.Page, "~/desktopmodules/DnnChat/scripts/moment.min.js");
    ClientResourceManager.RegisterScript(Parent.Page, "~/desktopmodules/DnnChat/scripts/DnnChat.js",150);
    

    示例来自:https://github.com/ChrisHammond/dnnCHAT/blob/master/View.ascx.cs

    【讨论】:

      【解决方案2】:

      我就是这样做的。我构建了这个辅助函数。 注意:这需要 DNN 6.1 及更高版本

      protected void InsertClientScripts(string scriptUrl, int priority = 100, ScriptLocation scriptLocation = ScriptLocation.Default)
      {
          switch (scriptLocation)
          {
              case ScriptLocation.Header:
                  ClientResourceManager.RegisterScript(this.Page, scriptUrl, priority, "DnnPageHeaderProvider");
                  break;
              case ScriptLocation.BodyTop:
                  ClientResourceManager.RegisterScript(this.Page, scriptUrl, priority, "DnnBodyProvider");
                  break;
              default:
                  ClientResourceManager.RegisterScript(this.Page, scriptUrl, priority, "DnnFormBottomProvider");
                  break;
          }
      }
      
      public enum ScriptLocation
      {
          Header,
          BodyTop,
          Default
      }
      

      这将允许您利用内置的客户端依赖框架。如果脚本已经存在,则避免插入脚本,允许压缩,可以指定位置(标题、正文顶部、正文底部),还可以设置脚本优先级。如您所见,默认优先级为 100(数字越小表示位置越高),脚本的默认位置为 body-bottom。祝你好运。

      【讨论】:

        【解决方案3】:

        我不相信 Chris Hammond 的回答会允许它利用允许压缩、最小化和组合文件的客户端依赖框架。所以,我认为最好使用 DNNJsInclude。你可以在这里了解更多:http://www.dotnetnuke.com/Resources/Wiki/Page/Client-Resource-Management-API.aspx

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多