【问题标题】:Need help passing props to jsx (adobe jsx) file from js file in React需要帮助将道具从 React 中的 js 文件传递​​给 jsx (adobe jsx) 文件
【发布时间】:2019-05-31 19:28:05
【问题描述】:

我使用了 create-cep-extension,它是一个基于 create-react-app 构建的 npm。它构建了一个可在任何 Adob​​e CC 应用程序中运行的引导扩展程序/面板。我在 Adob​​e Premiere Pro (PPRO) 中使用我的。我不知道如何将道具传递给 index.jsx 中的函数。这个 jsx 文件是 Adob​​e 的 jsx,它与 react jsx 文件无关,看起来一点也不像。我认为它基本上是一个非常旧的 javascript 版本。

我可以访问 jsx 文件并使用以下命令运行其中的代码:

loadExtendscript('./extendscript/index.jsx');

但我不能以这种方式传递任何道具。

我也可以用这个命令对 PPRO 执行通用的 jsx 命令:

evalExtendscript('alert(app.version)')

这是我将在实际 jsx 文件中使用的典型命令,但我还是不知道如何访问 index.jsx 中的函数并将 props 传递给它。

这是我想要工作的代码:

main.js

let profileObj = {
    message: 'ExendScript connected'
};

if (inCEPEnvironment()) {
    evalExtendscript('parseObj(' + JSON.stringify(profileObj) + ')')
    .then(result => alert(result))
    .catch(error => alert(error))
}


index.jsx

function parseObj(obj){
    alert(obj.message);
    // alert('hello');
};

在过去的两周里,我尝试了所有我能想到的方法,但都没有成功。

这里是 create-cep-extension 文档的链接,其中显示了“evalExtendscript”和“loadExtendscript”的示例: https://github.com/fusepilot/create-cep-extension

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    您需要在清单中添加您的 jsx 脚本路径,使用资源中的 <ScriptPath> 标记:

    <DispatchInfoList>
            <Extension Id="com.your.extension.id">
                <DispatchInfo >
                    <Resources>
                    <ScriptPath>./extendscript/index.jsx</ScriptPath>
    

    然后,您可以访问 index.jsx 中的所有内容和包含的文件:

    var myParam1 = 25;
    var myParam2 = 52;
    evalScript(`myFunction(${myParam1}, ${myParam2})`)
    

    【讨论】:

    • 非常感谢米格尔!!两周来我一直为此感到压力。
    • 跟进问题。你可以有多个 标签吗?我正在尝试添加另一个 ./extendscript/anotherScript.jsx 但它除了 index.jsx 之外什么都不识别。
    • 您可以在主 jsx 文件中执行此操作,它作为您可以编写包含或外部脚本引用的入口点,您也可以从前端传入它们以任意运行 JSX 代码也是。
    猜你喜欢
    • 2019-10-04
    • 2021-10-26
    • 2021-07-12
    • 1970-01-01
    • 2020-07-04
    • 2020-03-03
    • 2019-09-07
    相关资源
    最近更新 更多