100金币
本帖最后由 sammer110 于 2025-1-8 20:37 编辑
版本号:v16.4.1
产品:WebDesigner
目前项目设计为A页面是客户显示数据,点击页面B打开WebDesigner并加载A页面传过来的json预置到WebDesigner数据集中,让客户设置模板;
如:
let jsonData = [
{ Id: 1, Name: "Product 1", Price: 10.0 },
{ Id: 2, Name: "Product 2", Price: 15.5 },
{ Id: 3, Name: "Product 3", Price: 7.25 }
];
WebDesigner如何加载上述json到数据集,注意此时并不需要从后台调取数据,因为数据已经返回给A页面了。
<script>
// 声明 JSON 数据
let jsonData = [
{ Id: 1, Name: "Product 1", Price: 10.0 },
{ Id: 2, Name: "Product 2", Price: 15.5 },
{ Id: 3, Name: "Product 3", Price: 7.25 }
];
let name = "商品打印";
const reportName = `pfxhd\\${name}.rdlx`;
console.log(reportName);
/* Required for the ActiveReports Web Viewer */
var viewer = null;
GrapeCity.ActiveReports.Designer.create('#ar-web-designer', {
/*document: {
id: reportName,
type: { platform: 'rpx', type: 'report' },
},*/
storeUnsavedReport: false,
themes: { default: 'defaultDark' },
appBar: {
saveButton: { visible: true },
saveAsButton: { visible: false }
},
data: {
dataSets: { canModify: true },
dataSources: {
canModify: true , options: {
predefinedProviders: ['JSON']
}
}
},
units: 'cm',
preview: {
/* Required for the ActiveReports Web Viewer */
openViewer: ({ element, documentInfo: { id: documentId } }) => {
if (viewer) {
viewer.openReport(documentId);
return;
}
viewer = GrapeCity.ActiveReports.JSViewer.create({
element: '#' + element,
reportID: documentId,
renderFormat: options.preferredFormat || 'html',
reportService: {
url: 'api/reporting'
},
settings: {
zoomType: 'FitPage'
}
});
}
}
}).then((designer) => {
// 将 JSON 数据作为数据源添加到 WebDesigner
}).catch(error => {
console.error('初始化设计器时出错:', error);
});
</script>
|
|