简体   繁体   English

Alfresco-从服务器端JavaScript获取URL

[英]Alfresco - Getting the URL from server-side JavaScript

I'm trying to create a new page in Alfresco, but the tutorials gives to me the information that i have to create three files: new-page.get.js , new-page.html.ftl and new-page.get.xml , like Aikau - http://docs.alfresco.com/5.0/concepts/dev-extensions-share-page-creation.html 我正在尝试在Alfresco中创建一个新页面,但是这些教程为我提供了创建三个文件所需的信息: new-page.get.jsnew-page.html.ftlnew-page.get.xml ,例如Aikau - http: Aikau

But the javascript is different, for example, I try to get the current URL with: window.location.search or make console.log or alert . 但是javascript有所不同,例如,我尝试通过以下方式获取当前URL: window.location.search或将console.logalert But, in this three cases, I got "undefined" like "window is undefined" 但是,在这三种情况下,我得到“窗口未定义”之类的“未定义”

Why is this javascript different? 为什么这个javascript不同? What type of javascript is? 什么类型的javascript是? Where I can get tutorials, for example, to program this javascripts? 例如,在哪里可以获取教程来对此JavaScript进行编程?

I want to make a window.location.search to get the current URL , but if I don't have this command, what can I use for this effect? 我想创建一个window.location.search以获取当前URL,但是如果我没有此命令,该如何使用?

The JavaScript isn't different, the language itself is still the same. JavaScript没什么不同, 语言本身还是一样。

window , console and alert are just APIs supplied by browsers. windowconsolealert只是浏览器提供的API。 They aren't a native part of JavaScript. 它们不是JavaScript的本机部分。

The documentation you linked to should be your starting point for figuring how what APIs are available. 链接到的文档应该是确定如何使用API​​的起点。

Normally, the Alfresco way wouldn't be to get the raw URL. 通常,Alfresco方式不是获取原始URL。 Instead, you should be using the built-in argument processing 相反,您应该使用内置参数处理

Since Alfresco itself is open source, we can look at Alfresco for some examples! 由于Alfresco本身是开源的,因此我们可以看一下Alfresco的一些示例! So, starting with the groups get webscript , we see a URL pattern defined as: 因此,从组获取webscript开始 ,我们看到一个URL模式定义为:

<url>/api/groups?shortNameFilter={shortNameFilter?}&zone={zone?}&maxItems={maxItems?}&skipCount={skipCount?}&sortBy={sortBy?}</url>

With that, we see a whole bunch of pre-defined parameters on the URL. 这样,我们在URL上看到了很多预定义的参数。

Next, we look at the javascript controller behind that webscript , and we see things like: 接下来,我们看一下该webscript后面javascript控制器 ,然后看到类似以下内容:

var shortNameFilter = args["shortNameFilter"];
var zone = args["zone"];

Those URL parameters are then parsed into your webscript in the args variable, available for you to fetch as a hash. 然后,将这些URL参数解析为args变量中的Web脚本,您可以将其作为哈希值获取。

No need to do any raw URL munging yourself, if you define your webscript correctly the framework does it all for you! 无需自己动手做任何原始的URL,如果您正确定义了Web脚本,则框架将为您完成所有工作!

You can get the server URL in the Javascript web script (on the backend) by 您可以通过以下方式在Javascript网络脚本(在后端)中获取服务器URL:

var path = url.getServer()

http://localhost:8080 will be returned for example 例如将返回http://localhost:8080

Here is the list of available the methods - you can concatenate them to get a direct URL: 以下是可用方法的列表 -您可以将它们串联以获取直接URL:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM