说明:
此Demo展示了如何给异步函数设置触发器的方法。
在SpreadJS中,异步函数有三种不同的触发重算的方式,参考API:
https://demo.grapecity.com.cn/sp ... onEvaluateMode.html
当异步函数的evaluateMode方法返回值为GC.Spread.CalcEngine.Functions.AsyncFunctionEvaluateMode.onRecalculation时,
函数会根据引用的单元格变化而触发重算。
核心代码(完整示例见附件):
- var MyFun1 = function () {
- };
- MyFun1.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("MyFUN_1", 1, 255);
- MyFun1.prototype.defaultValue = function () {
- return "Loading...";
- };
- MyFun1.prototype.evaluateAsync = function (context) {
- console.log("MyFun_1 evaluateAsync");
- context.setAsyncResult(Math.random());
- };
- // evaluateMode
- MyFun1.prototype.evaluateMode = function () {
- return GC.Spread.CalcEngine.Functions.AsyncFunctionEvaluateMode.onRecalculation;
- };
-
-
- var MyFun2 = function () {
- };
- MyFun2.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("MyFUN_2", 1, 255);
- MyFun2.prototype.defaultValue = function () {
- return "Loading...";
- };
- MyFun2.prototype.evaluateAsync = function (context) {
- console.log("MyFun_2 evaluateAsync");
- context.setAsyncResult(Math.random());
- };
- // evaluateMode
- MyFun2.prototype.evaluateMode = function () {
- return GC.Spread.CalcEngine.Functions.AsyncFunctionEvaluateMode.onRecalculation;
- };
复制代码
|
|