1

我想使用 RenderJsHere() 渲染两个不同的 javascript 文件包。

我已将它放在页面上的两个不同位置,但它在两个位置都显示了所有文件(第 1 组 + 第 2 组文件)。谁能指导我如何使用 RenderJsHere() 渲染两组不同的文件?

下面是一些示例代码。

谢谢,

@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using ClientDependency.Core.Mvc
<!DOCTYPE html>
<html>
<head>                        
    @Html.RenderCssHere()

     @{
        Html.RequiresJs("~/content/js/jquery-3.5.1.js", 1);        
     }
    @Html.RenderJsHere() ===========  **1st group of files in header**

</head>
<body>
    Some HTML here

    Bottom of page

    @{
        Html.RequiresJs("~/content/js/bootstrap.js", 1);
        Html.RequiresJs("~/content/js/jquery.lazy.js", 2);
        Html.RequiresJs("~/content/js/slick.js", 3);
        Html.RequiresJs("~/content/js/app.js", 4);
        Html.RequiresJs("~/content/js/myjs.js", 5);
    }
    @Html.RenderJsHere() **2nd group of files at last in page**

</body>
</html>
4

2 回答 2

0

看看你如何在这里创建命名包:umbraco 中的 ClientDependency 不包括我的包- 然后你可以在任何你想要的地方渲染单个包。

于 2020-10-27T15:40:15.800 回答
0

您可以使用RequiresJsBundle来设置要使用的命名包。然后使用RenderJsHere

Html.RequiresJsBundle("customjs1"); 
@Html.RenderJsHere()

https://github.com/Shazwazza/ClientDependency/blob/b5ba8cf6fbe476365b948888478e4389dbd0f710/ClientDependency.Mvc/HtmlHelperExtensions.cs

于 2020-10-27T21:53:59.730 回答