【问题标题】:how to save stimulsoft report js to server in angular?如何以角度将stimulsoft报告js保存到服务器?
【发布时间】:2021-11-07 10:51:34
【问题描述】:

我有一个报表设计器组件并将方法分配给onSaveReport 事件,但在该方法中我的组件成员是undefined

    options: any;
    designer: any;
    public document: ReportDocument;

    reportBody = '';
    constructor() {

    }

    ngOnInit() {
        this.document = new ReportDocument();
        this.options = new Stimulsoft.Designer.StiDesignerOptions();
        this.options.appearance.fullScreenMode = false;

        this.designer = new Stimulsoft.Designer.StiDesigner(this.options, 'StiDesigner', false);
        var report = new Stimulsoft.Report.StiReport();
        var json = { "DataSet": [{ Id: "a", Name: "A" }] }
        var dataSet = new Stimulsoft.System.Data.DataSet("JSON");

        dataSet.readJson(json)
        report.regData("JSON", "JSON", dataSet);

        report.dictionary.synchronize();
        this.designer.report = report;
        this.designer.renderHtml('designer');
        this.designer.onSaveReport = this.onReportSave;
    }

    private onReportSave(e: any) {
        this.document.body = e.report.saveToJsonString(); // error is here
        
    }
}

这是错误:

无法设置未定义的属性(设置'body') TypeError:无法在 $.onReportSave [as onSaveReport] (http://localhost:4200/features-stimulsoft-report-stimulsoft-report-module.js:1206:28) 处设置未定义的属性(设置“body”)$ .invokeSaveReport (http://localhost:4200/assets/lazyBundles/stimulsoft/stimulsoft.designer.js:30:82619) 在 $.raiseCallbackEventAsync (http://localhost:4200/assets/lazyBundles/stimulsoft/stimulsoft.designer. js:30:86029) 在 http://localhost:4200/assets/lazyBundles/stimulsoft/stimulsoft.designer.js:30:78818 在 ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:12178:35 ) 在 Object.onInvokeTask (http://localhost:4200/vendor.js:72788:33) 在 ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:12177:40) 在 Zone.runTask (http: //localhost:4200/polyfills.js:11946:51) 在invokeTask (http://localhost:4200/polyfills.js:12259:38) 在ZoneTask.invoke (http://localhost:4200/polyfills.js: 12248:52)`

【问题讨论】:

    标签: javascript angular typescript stimulsoft


    【解决方案1】:

    您无权访问 thisonReportSave 函数内的类,因为您将函数引用传递给 onSaveReport 并且由于设计器在函数内调用您的函数 this 属于设计器而不是您的类,并且这就是错误 this.document 未定义的原因,您从未定义中调用 body,但您可以使用绑定属性更改它

    this.designer.onSaveReport = this.onReportSave.bind(this);
    

    现在您将函数内的this 设置为您班级的this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多