Update forEach

This commit is contained in:
ckcz123 2020-05-08 21:07:17 +08:00
parent 78f4210eb7
commit dcc6d39927
2 changed files with 6 additions and 5 deletions

View File

@ -1954,7 +1954,7 @@ return '{"type": "for", "name": "'+expression_0+'", "from": "'+EvalString_0+'",
*/; */;
forEach_s forEach_s
: '循环遍历' ': ' expression '在列表' JsonEvalString '中' BGNL? Newline action+ BEND Newline : '循环遍历' ': 以' expression '逐项读取列表' JsonEvalString BGNL? Newline action+ BEND Newline
/* forEach_s /* forEach_s
tooltip : forEach循环遍历列表 tooltip : forEach循环遍历列表

View File

@ -1858,15 +1858,16 @@ events.prototype._action_for = function (data, x, y, prefix) {
core.setFlag(toName, data.to); core.setFlag(toName, data.to);
core.setFlag(stepName, data.step); core.setFlag(stepName, data.step);
var condition = "(function () {"+ var condition = "(function () {"+
"var clearAndReturn = function (v) { if (!v) { core.removeFlag('"+toName+"'); core.removeFlag('"+stepName+"'); } return v; };"+
"var to = core.calValue(core.getFlag('" + toName + "'));"+ "var to = core.calValue(core.getFlag('" + toName + "'));"+
"var step = core.calValue(core.getFlag('" + stepName + "'));"+ "var step = core.calValue(core.getFlag('" + stepName + "'));"+
"if (typeof step != 'number' || typeof to != 'number') return false;"+ "if (typeof step != 'number' || typeof to != 'number') return clearAndReturn(false);"+
"if (step == 0) return true;"+ "if (step == 0) return clearAndReturn(true);"+
"var currentValue = core.calValue('switch:'+'" + data.name.substring(7) + "', '"+prefix+"');"+ "var currentValue = core.calValue('switch:'+'" + data.name.substring(7) + "', '"+prefix+"');"+
"currentValue += step;"+ "currentValue += step;"+
"core.events._setValue_setSwitch('switch:'+'" + data.name.substring(7) + "', currentValue, '"+prefix+"');"+ "core.events._setValue_setSwitch('switch:'+'" + data.name.substring(7) + "', currentValue, '"+prefix+"');"+
"if (step > 0) { return currentValue <= to; }"+ "if (step > 0) { return clearAndReturn(currentValue <= to); }"+
"else { return currentValue >= to; }"+ "else { return clearAndReturn(currentValue >= to); }"+
"})()"; "})()";
return this._action_dowhile({"condition": condition, "data": data.data}, x, y, prefix); return this._action_dowhile({"condition": condition, "data": data.data}, x, y, prefix);
} }