从 evalScript 函数返回变量的问题

西蒙内托斯 希腊人

我正在Photoshop 开发CEP HTML 面板,我想先检查是否有任何打开的文档,然后我的面板执行它必须执行的操作。所以我在我的index.js 中做了这样的事情来测试我是否得到了正确的结果。变量返回未定义。知道我做错了什么吗?psDocumentsLength

(function()
{
   'use strict';

    var csInterface = new CSInterface();
    var psDocumentsLength; //1//

    function init()
    {
        themeManager.init();
        $(document).ready(function()
        {
            check_PSDocumentsLength();
            alert(psDocumentsLength); //4//
        });
    };

    init();

    function check_PSDocumentsLength() //2//
    {
        var chosenFunction = 'checkDocumentsLength()';
        csInterface.evalScript(chosenFunction, function(result)
        {
            psDocumentsLength = result; //3//
        });
    };

}());
西蒙内托斯 希腊人

考虑什么谢尔盖Kritskiy graphicdesignstackexchange有关问题的代码异步,我尝试添加setTimeout后,check_PSDocumentsLength()函数调用和它的工作!所以我的代码现在看起来像这样......

    (function()
    {
       'use strict';

        var csInterface = new CSInterface();
        var psDocumentsLength; //1//

        function init()
        {
            themeManager.init();
            $(document).ready(function()
            {
                check_PSDocumentsLength();
                setTimeout(function()
                {
                    alert(psDocumentsLength);
                }, 1000); //4//
            });
        };

        init();

        function check_PSDocumentsLength() //2//
        {
            var chosenFunction = 'checkDocumentsLength()';
            csInterface.evalScript(chosenFunction, function(result)
            {
                psDocumentsLength = result; //3//
            });
        };

    }());

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章