我有一个问题。我的start函数中的intervalValue是未定义的。但在微流函数中,它是我想要的价值。如何将微流函数中的值返回到启动函数。我已经尝试了javascript的基本全局和返回实现,但这不起作用,并且dojo.global不够清楚,我知道如何实现。所有帮助表示赞赏。请参阅下面的代码:
start : function() {
this.addOnLoad(dojo.hitch(this, function() { //make sure the thing only starts when completely loaded!
if (this.once)
this.handle = window.setTimeout(dojo.hitch(this, function() {
this.intervalexecute();
console.log("addOnLoad " + this.intervalValue);
this.execute();
this.stopped = true;
}), this.intervalValue);
else {
this.intervalexecute();
console.log("addOnLoad " + this.intervalValue);
if (this.startatonce)
this.execute(); //invoke directly as well
this.handle = window.setInterval(dojo.hitch(this, this.execute), this.intervalValue);
}
}));
},
intervalexecute : function() {
if (this.dataobject != null && this.dataobject.getGUID && this.dataobject.getGUID())
{
//microflow set, not already calling a microflow
mx.processor.xasAction({
error : function() {
logger.error(this.id + "error: XAS error executing microflow");
},
actionname : this.intervalmicroflow,
applyto : 'selection',
guids : [this.dataobject.getGUID()],
callback : dojo.hitch(this, this.microflowresult)
});
}
},
microflowresult: function(result) {
if (result) {
this.intervalValue = dojo.fromJson(dojo.isIE ? result.xhr.responseText : result.xhr.response).actionResult;
console.log("result: " + this.intervalValue);
}
},
答案 0 :(得分:0)
未设置原因间隔值是因为microflowresult是异步函数。 start中的日志记录语句在调用microflowresult之前执行。
您需要让回调对intervalValue进行任何处理。