淘汰赛JS +母版页/视图

发布于 2024-11-18 13:37:32 字数 2267 浏览 3 评论 0原文

怀疑这是可能的,因为我没有单页应用程序,但我制作的几乎每个视图都包含 80% 相同的 css/javascript,所以有什么方法可以告诉 knockoutJS 一个主视图,其他所有内容都会填充?

我对此表示怀疑,因为这几乎就是一页应用程序的用途...我最希望的是使用 Combres 之类的东西将我所有不变的东西组合到每种类型的一个资源文件中...

==编辑==

添加我的意思的例子,我很确定我无法注入到多个区域,如下所示,但这里有一个例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>Master Page</title>
        <link type="text/css" rel="stylesheet" href="../Assets/Styles/main.css">
        <link type="text/css" rel="stylesheet" href="../Assets/Styles/Themes/simple.css">
        <link type="text/css" rel="stylesheet" href="../Assets/Styles/jquery.qtip.min.css">
        {Per Page Css Here}
    </head>
    <body>
        {Per Page Content Here}

        <script type="text/javascript" src="../Scripts/Libs/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery-ui-1.8.13.custom.min.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery.tmpl.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery.qtip.pack.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/knockout-1.2.1.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/knockout-external-templates.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/cufon-yui.js"></script>

        {Per Page Scripts Here}
    </body>
</html>

<!-- View 1 -->
<link type="text/css" rel="stylesheet" href="../Assets/Styles/Views/view1.css">
<h1>Some Content</h1>
<script type="text/javascript" src="../Scripts/view1.js"></script>

<!-- View 2 -->
<link type="text/css" rel="stylesheet" href="../Assets/Styles/Views/view2.css">
<h1>Some Other Content</h1>
<script type="text/javascript" src="../Scripts/view2.js"></script>

再说一次,如果我不能这样做,它不是一个游戏破坏者,只是不想如果我更新 jquery 版本等,则必须更新每个视图...

Doubt this is possible as I don't have a 1 page app, but pretty much every view I make contains 80% of the same css/javascript, so is there any way I could tell knockoutJS a master view which everything else would just populate?

I doubt it as this is pretty much what a 1 page app is for... best I can hope for is to use something like Combres to combine all my non-changing stuff together into one resource file per type...

== EDIT ==

Adding example of what I mean, I am pretty sure I wouldn't be able to inject into multiple areas like shown below, but here is an example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>Master Page</title>
        <link type="text/css" rel="stylesheet" href="../Assets/Styles/main.css">
        <link type="text/css" rel="stylesheet" href="../Assets/Styles/Themes/simple.css">
        <link type="text/css" rel="stylesheet" href="../Assets/Styles/jquery.qtip.min.css">
        {Per Page Css Here}
    </head>
    <body>
        {Per Page Content Here}

        <script type="text/javascript" src="../Scripts/Libs/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery-ui-1.8.13.custom.min.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery.tmpl.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/jquery.qtip.pack.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/knockout-1.2.1.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/knockout-external-templates.js"></script>
        <script type="text/javascript" src="../Scripts/Libs/cufon-yui.js"></script>

        {Per Page Scripts Here}
    </body>
</html>

<!-- View 1 -->
<link type="text/css" rel="stylesheet" href="../Assets/Styles/Views/view1.css">
<h1>Some Content</h1>
<script type="text/javascript" src="../Scripts/view1.js"></script>

<!-- View 2 -->
<link type="text/css" rel="stylesheet" href="../Assets/Styles/Views/view2.css">
<h1>Some Other Content</h1>
<script type="text/javascript" src="../Scripts/view2.js"></script>

Again, if I cannot do this its not a game breaker, just dont want to have to update every view if I update the jquery version etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-11-25 13:37:32

您可以声明与视图中的每个视图相关的 Javascript 代码以及母版页中的通用代码。然后从母版页调用该代码并使用 ko.applybindings 绑定它们。

You could declare your Javascript code relevant to each view in your views and the common code in your master page. Then call that bit of code from your master page and bind them using ko.applybindings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文