在不同的库中调用 JavaScript 函数

Bil*_*l F 0 javascript xpages

在我看来,这应该是可能的。在XPage应用程序中,我有两个ServerSide JavaScript 库jsMainjsSave。在 jsMain 我有这个脚本:

function thisAction(msg:String){
    try{

    switch(msg){
    case "Save" :
        print("This action = " + msg);
        if (jsSave.processAction()){
            print("jsSave.processAction returned true");
            return true;
            break;
        }else{
            print("jsSave.processAction returned false");
            return false;
            break;
        }
    default:
        print("In default msg is " + msg);
        return false;
        break;
    }
    }catch(e){
        print("thisAction Failed in jsMain " + e.toString())
    }
}
Run Code Online (Sandbox Code Playgroud)

在 XPage 上的一个按钮中,我调用thisAction("Save")它并调用 thisAction 函数,现在当 msg 为 Save 时,我想调用该函数,processAction但它驻留在 JS 库 jsSave 中。我上面的失败并出现错误: thisAction Failed in jsMain 'jsSave' not found

那么有没有办法告诉这段代码 processAction 在不同的 SSJS 库中?

小智 5

添加

import jsSave
Run Code Online (Sandbox Code Playgroud)

在您的 jsMain 库之上,没有引号,没有文件扩展名:您将能够使用 jsMain 中在 jsSave 中声明的函数。