从evalScript函数返回变量的问题

问题描述 投票:0回答:1

我正在为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// }); }; }());
javascript photoshop photoshop-script
1个回答
0
投票
考虑到

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// }); }; }());

© www.soinside.com 2019 - 2024. All rights reserved.