找回密码
 立即注册

QQ登录

只需一步,快速开始

kelvinChen
金牌服务用户   /  发表于:2024-3-14 16:57  /   查看:720  /  回复:10
1金币
本帖最后由 Richard.Huang 于 2024-3-15 09:30 编辑

产品:SpreadJS
版本:V16.2.4

在设计器设计表格通过spread拿到当前表格的toJson,可以保存
但是进入另一个工作簿,修改当前工作簿,点击获取当前工作簿spread的toJson,发现拿到的toJson是上一个工作簿的toJson,是否会存在有缓存的现象
第一个工作簿(正确保存)
image.png643614501.png image.png673434142.png
第二个工作簿(保存后变成了第一个工作簿的内容,经过查看,是spread.toJSON()拿到上一个toJson数据,但是进入两个不同工作簿是通过路由的控制的)
image.png333605040.png image.png438230590.png

最佳答案

查看完整内容

您好,需要注意的是组件是否只初始化了一次,组件中的SpreadJS是否是跟随组件的初始化而初始化的,如果destroy掉,在第二次打开组件的时候是否会判断SpreadJS对象还存在,若不存在则需要重新初始化SpreadJS对象。

10 个回复

倒序浏览
最佳答案
最佳答案
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-3-14 16:57:39
来自 8#
您好,需要注意的是组件是否只初始化了一次,组件中的SpreadJS是否是跟随组件的初始化而初始化的,如果destroy掉,在第二次打开组件的时候是否会判断SpreadJS对象还存在,若不存在则需要重新初始化SpreadJS对象。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-3-14 17:44:22
2#
您好,有可能是您在切换的时候,spread对象并没有发生改变,所以这时toJSON的结果仍然是第一次spread对象的结果,建议您从代码层面排查一下看看切换后的spread对象是否正确。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
kelvinChen
金牌服务用户   /  发表于:2024-3-15 14:01:03
3#
我看了看确实好像时spread对象是同一个,但是我是使用路由跳转的,应该没错进入组件都重新初
  1. async mounted() {
  2.     if (!this.designer) {
  3.       let config = this.initRibbon();
  4.       let designer = new GC.Spread.Sheets.Designer.Designer(
  5.         document.getElementById("designer-content"),
  6.         config
  7.       );
  8.       this.designerInitialized(designer);
  9.     }
  10.     this.initRegObj();
  11.     this.initRule();
  12.     console.log(this.regObj);
  13.     // 加载编辑数据
  14.     console.log(this.$route);
  15.     console.log(this.$route.query);
  16.     console.log(this.$route.query.type);
  17.     const { type, reportId } = this.$route.query;
  18.     if (type == "edit" && reportId) {
  19.       let styleRes = {};
  20.       // 字段数据
  21.       let strRes = {
  22.         $schema: "http://json-schema.org/draft-04/schema#",
  23.         properties: {
  24.           name: { dataFieldType: "text", type: "string" },
  25.           age: { dataFieldType: "text", type: "string" },
  26.           height: { dataFieldType: "text", type: "string" },
  27.           sex: { dataFieldType: "text", type: "string" },
  28.         },
  29.         type: "object",
  30.       };
  31.       //获取报表样式与源数据
  32.       let {
  33.         data: {
  34.           data: { reportStyle, dictionaryList },
  35.         },
  36.         status,
  37.       } = await seGetReportAllData(reportId);
  38.       if (status === 200) {
  39.         //需要替换数据
  40.         reportStyle ? (styleRes = JSON.parse(reportStyle.reportJson)) : "";
  41.         let properties = {};
  42.         dictionaryList.forEach((item) => {
  43.           properties[item.name] = {
  44.             dataFieldType: item.dataFieldType,
  45.             type: item.type,
  46.             id: item.id,
  47.             properties: item.extra ? JSON.parse(item.extra) : null,
  48.           };
  49.         });
  50.         strRes.properties = properties;
  51.       }
  52.       this.curSource = dictionaryList;
  53.       this.initDesigner(styleRes, strRes);
  54.     }
  55.     this.isLoading = false;
  56.     this.listenCellEvent();
  57.   },

  58. designerInitialized: function (designer) {
  59.       this.designer = designer;
  60.       this.spread = designer.getWorkbook();
  61.       let config = GC.Spread.Sheets.Designer.DefaultConfig;
  62.       let json = this.spread.toJSON();
  63.       console.log("json", json);
  64.       // 添加自定义tab
  65.       designer.bind(
  66.         GC.Spread.Sheets.Designer.Events.FileLoaded,
  67.         (event, data) => {
  68.           this.spread = designer.getWorkbook();
  69.           this.listenCellEvent();
  70.           console.log("spread", this.spread);
  71.         }
  72.       );
  73.       this.config = config;
  74.       this.spread.options.newTabVisible = true;
  75.       this.spread.options.tabNavigationVisible = false;
  76.       this.spread.options.scrollbarMaxAlign = true;
  77.       this.spread.options.isProtected = true;
  78.       this.spread.invalidateLayout();
  79.       this.spread.repaint();
  80.       this.initSpreadSheet();
  81.       this.initRibbon(config);
  82.       // console.log("calculate",this.spread.options.calcOnDemand)
  83.     },


  84. //保存的获取toJson
  85. var spread1 = this.spread;
  86.       this.jsonStr = JSON.stringify(spread1.toJSON());



复制代码
始化,我把组件贴出来,可以帮忙看看吗
回复 使用道具 举报
kelvinChen
金牌服务用户   /  发表于:2024-3-15 14:05:16
4#
我尝试过在销毁组件的时候spread = null,然后再次进来toJson旧拿不到,应该是使用同一spread对象,所以我应该怎么设计才能每次进入组件都重新获取新的spread
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-3-15 16:07:12
5#
您好,一个最简单的方式是在切换组件的时候将之前存储的所有SpreadJS相关的对象destroy掉,然后在新的组件中判断对象是否已经销毁,然后创建一个新的SpreadJS对象挂载在组件中。

参考链接:https://demo.grapecity.com.cn/sp ... er.Designer#destroy
https://demo.grapecity.com.cn/sp ... ts.Workbook#destroy
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
kelvinChen
金牌服务用户   /  发表于:2024-3-16 09:05:18
6#
我退出组件的时候destory了,再次进入的时候提示找不到组件,明明是进入组件的时候已经初始化了
回复 使用道具 举报
nobt
论坛元老   /  发表于:2024-3-16 09:07:12
7#
新进入时每次都对spread对向重新fromJSON
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-3-21 16:59:48
9#
您好,请问您的问题是否已经解决,如果仍未解决,欢迎继续回帖,我们来协助调研。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
kelvinChen
金牌服务用户   /  发表于:2024-3-22 17:41:31
10#
已解决
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部