我正在为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//
});
};
}());
stackexchange上stackdesign]上graphicdesign]上的Sergey Kritskiy said,我试图在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//
});
};
}());