我正在为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 说在graphicdesign上stackexchange有关问题的代码异步,我尝试添加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] 删除。
我来说两句