gpt4 book ai didi

web-applications - 使用 ExtJS 构建的 WebApp 中的 URL 导航

转载 作者:行者123 更新时间:2023-12-04 19:15:15 27 4
gpt4 key购买 nike

当您使用 ExtJS(带有 MVC 和 Viewport)开发 Web 应用程序时,通常无法导航:页面中的每个项目(按钮、文本字段、文本区域...)都绑定(bind)到 View Controller 的特定方法.
因此,当您“浏览”应用程序时,原始 URL 始终是相同的并且不会改变。

现在,以一个带有以下按钮的标题菜单栏的应用程序为例:

Home | Setup | Archive

应用程序的原始 URL 采用以下内容:
http://www.mydomain.com/webapp

此时,当有人单击 Home 或 Setup 或 Archive 菜单时,某个 View 会显示到中心区域,并且 URL 应更改为
http://www.mydomain.com/webapp/[home|setup|archive]

因此,如果我单击设置菜单,地址栏中应显示以下 URL:
http://www.mydomain.com/webapp/setup

此外,如果我从另一个 URL 在地址栏中键入相同的 URL,则应该显示相同的页面。

但目前我的 webapp 仍然保留为 ' http://www.mydomain.com/webapp ' 显示请求的 View 。 (例如,MyApp.view.Setup)。

这就是重点:如何开发带有 URL 导航的 webapp(使用 ExtJS、MVC 和 Viewport)?是否可以不将 javascript/html 代码嵌套到其他 PHP/Ruby/Python/$RANDOM_SERVER_LANGUAGE 中? (我想通过服务器端拆分客户端)

这个实现已经存在:它是 ExtJS API Documentation .如果我是对的,那么没有提供请求页面的服务器端应用程序或 .htaccess。
事实上,主目录中有一个名为“source”的文件夹,其中包含每个类的 HTML 文件。
他们是怎么做到的?

提前致谢。
威尔克

最佳答案

好的,我自己找到了解决方案:P

那么,这种事情可以通过以下方式完成:

HTML 部分

<!DOCTYPE html>
<html>
<head>
<title>Stackoverflow</title>
<link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
<script type="text/javascript" src="../extjs-4.1.0/ext-all.js"> </script>
<script type="text/javascript" src="sof.js"> </script>
</head>
<body>
<a href="#!photos.html">Photos</a>
<a href="#!info.html">Info</a>
<a href="#!aboutme.html">About Me</a>

<div id="results"></div>
</body>

Javascript 部分,使用 ExtJS 框架 (sof.js)
// Loads each HTML part with an AJAX request
function loadAnchor (url) {
Ext.Ajax.request ({
url: url ,
success: function (res) {
// Edits results div with the new HTML part
var r = Ext.get ('results');
r.dom.innerHTML = res.responseText;
}
});
}


Ext.onReady (function () {
var anchors = document.getElementsByTagName ('a');

Ext.each (anchors, function (a) {
a = Ext.get (a);
// Attaches to each anchor the following function on click event
a.on ('click', function (ev, anchor) {
// Splits the hash, keeping the HTML requested
var url = anchor.getAttribute('href').split('#!')[1];
loadAnchor (url);
});
});

// This is done without clicking an anchor, but by inserting directly the full URI
// E.g.: http://www.mydomain.com/webapp/index.html#!info.html instead of clicking the anchor Info
var url = document.location.hash.split('#!')[1];
loadAnchor (url);
});

如您所见,每个 anchor 都绑定(bind)了一个 javascript 函数,该函数通过 AJAX 请求加载请求的资源。
然后,使用响应(可能是 HTML 代码或 JSON、XML 等)修改某个容器(例如 div)。

然而,这件事必须通过像 Apache 这样的服务器 Web 来完成,但没有服务器应用程序:事实上,每个资源都可以是纯 HTML 文件,并且不需要服务器应用程序来提供这些文件。

有关详细信息,请参阅:
  • Anchored based URL navigation
  • Making AJAX Applications Crawlable
  • 关于web-applications - 使用 ExtJS 构建的 WebApp 中的 URL 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10499595/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com