找回密码
 立即注册

QQ登录

只需一步,快速开始

98785020

注册会员

8

主题

25

帖子

99

积分

注册会员

积分
99
98785020
注册会员   /  发表于:2018-1-16 16:03  /   查看:3050  /  回复:3
本帖最后由 98785020 于 2018-1-16 17:20 编辑

通过spread.fromJSON加载一个远程ssjson文件,若该文件里含有自定义公式,且这个公式非全局公式,该公式无法被执行
代码如下

  1. var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
  2. spread.addCustomFunction(new GetTimeFromServer());
  3. this.$request.get("/test.ssjson").then((_result) => {
  4.          spread.suspendPaint();
  5.          spread.fromJSON(_result);
  6.          /***
  7.          for(var index in spread.sheets){
  8.               //设置局部公式
  9.               spread.sheets[index].addCustomFunction(new GetTimeFromServer());
  10.          }
  11.           **/
  12.           spread.resumePaint();
  13.      }
  14.                 })
复制代码
GetTimeFromServer 为异步公式继承至GC.Spread.CalcEngine.Functions.AsyncFunction

无论是spread.addCustomFunction还是 spread.sheets[index].addCustomFunction GetTimeFromServer 第一次加载后都无法执行

若通过 GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEFROMSERVER", new GetTimeFromServer()); 则可以执行




3 个回复

倒序浏览
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-1-16 17:38:48
沙发
这个是执行顺序的问题,应spread.sheets[index].addCustomFunction不行的原因是fromjson的时候公式就会被执行一次而spread.sheets[index].addCustomFunction肯定是在fromjson之后,所以执行就时候就发现公式不存在了再次addCustomFunction已经晚了。
spread.addCustomFunction是因为fromjson的时候会将spread整个替换,所以之前设置在spread上面的信息都会不见。
而 GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEFROMSERVER", new GetTimeFromServer());是在全局进行注册,所以可以使用。
回复 使用道具 举报
98785020
注册会员   /  发表于:2018-1-17 13:10:41
板凳
ClarkPan 发表于 2018-1-16 17:38
这个是执行顺序的问题,应spread.sheets.addCustomFunction不行的原因是fromjson的时候公式就会被执行一次 ...

那spread有什么方法,可以手动去触发这些公式去执行一次么?
回复 使用道具 举报
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-1-17 16:12:02
地板
您好,您可以这样做,在toJSON之前在自定义方法中定义typename,这样您fromjson之后就不需要再做
spread.addCustomFunction或者GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction这一步了
typename的定义请参考:
http://demo.gcpowertools.com.cn/ ... customItemSerialize
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部