本文介绍了“未定义".在< aui:script>内部堵塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试扩展现有Liferay Portlet的某些功能.作为其中的一部分,我想使用Alloy UI来修改portlet中字段的值.有一个预先存在的<aui:script>块,我想在其中定义我的自定义函数.我继续尝试使用A.one('element'),但是收到错误未定义A". A.one()在同一.jsp文件中的其他位置使用,尽管未在<aui:script>块中使用,并且其功能正常.

I'm trying to extend some functionality of an existing Liferay portlet. As part of this, I would like to use Alloy UI to modify the value of a field in the portlet. There's a pre-existing <aui:script> block where I would like to define my custom function. I went ahead and tried using A.one('element'), but I am receiving the error "A is not defined." A.one() is used elsewhere in the same .jsp file, though not in an <aui:script> block, and it functions as expected.

我尝试使用Google搜索此问题无济于事.我尝试的一种解决方案是在元素块中包含"use"语句,但是当从jsp调用时,这使该块中的所有函数都不确定.

I have tried Googling this problem to no avail. One solution that I tried was to include the "use" statement in the element block, but this made all of the functions in that block undefined when called from the jsp.

使用"语句的意思是这样的:

What I mean by the "use" statement is this:

<aui:script use="aui-node,aui-base">
    // ... script
</aui:script>

以下是我要做的事情的粗略概述:

Here's a rough outline of what I'm trying to do:

<aui:script>
    function save(){
        // This is where I'm getting the 'A is not defined' error.
        var titleNode = A.one('input[name=title]');

        if (titleNode) {
            // do stuff with titleNode
            var titleVal = titleNode.val();
            var titleSubstr = titleVal.substring(0, titleSubstr.lastIndexOf('/'));
            titleNode.val(titleSubstr);
        }

        // other save-related code here
    }

    function otherFunction() {
        // some other functionality
    }
</aui:script>

推荐答案

<aui:script>标记输出

AUI().use(function(A) {
}

仅当您通过use属性提供依赖项时.像

only if you provide dependencies via use attribute. Like

<aui:script use="aui-base">
    // your code here
</aui:script>

如果这样做,您将拥有

<script type="text/javascript">
    AUI().use('aui-base', function(A) {
        // your code here
    }
</script>

结果为

.但是在这种情况下,您在内部声明的所有函数都不会是全局的.使其成为全局呼叫

as a result. But in this case, all functions you declare inside will not be global. To make them global call

Liferay.provide(window, 'functionName', function() {
    // function body
});

内部<aui:script/>

如果客户端可以具有IE< = 7,则<aui:script use="aui-base"/>比手动调用AUI().use(function(A) {})更好,这对于AUI().use()无法正常工作.对于IE 6,7,<aui:script use="aui-base>将输出AUI().ready('aui-base', function(A) {});,该版本将在旧的浏览器中运行.

Also <aui:script use="aui-base"/> is better than manually calling AUI().use(function(A) {}) if client can have IE <= 7, that doesn't work correctly with AUI().use(). In case of IE 6,7 <aui:script use="aui-base> will output AUI().ready('aui-base', function(A) {}); which will work in old browsers.

这篇关于“未定义".在&lt; aui:script&gt;内部堵塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:40