我有两个不同的 web api 项目。
一个将充当“API”,一个将充当“使用 angularjs 的前端”。
如何在我的项目中实现 jsreport?
是否可以通过从另一个 api 项目中获取数据来使用 angularjs 在 web api 前端实现 jsreport?
请帮助我找到正确的解决方案。
因为我已经看到 jsreport 非常适合生成 pdf 格式的前端报告。
我正在使用 Microsoft Visual Studio Professional 2013。
提前致谢。
我有两个不同的 web api 项目。
一个将充当“API”,一个将充当“使用 angularjs 的前端”。
如何在我的项目中实现 jsreport?
是否可以通过从另一个 api 项目中获取数据来使用 angularjs 在 web api 前端实现 jsreport?
请帮助我找到正确的解决方案。
因为我已经看到 jsreport 非常适合生成 pdf 格式的前端报告。
我正在使用 Microsoft Visual Studio Professional 2013。
提前致谢。
最简单的方法是使用通过 NuGet 提供的 JsReport .NET 集成,并使用您的 Web API 使用的服务方法为从后端对 JsReport 的请求生成数据。文档非常好。
是的,您可以使用 Web API 作为报告的数据提供者并生成报告。您可以从此处获取有关 Jsreport 入门的文章。
这是使用 api 在 Angular 应用程序中生成 JSReport 的方法
app.controller('mainCtrl' , function($scope, $http){
$scope.yourData = {
//your data goes here
}
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:3001/api/report",
"method": "POST",
"headers":{
"content-type": "application/json",
"cache-control": "no-cache"
},
"processData": false,
"data": {"template": { "shortid" : "short-id-of-your-template", "recipe": 'html'},"data": yourData
}
}
}
$http(settings).then(function(responce){
$scope.htmlresponce = responce.data
console.log(responce.data)//your html of jsreport will go here
})
}
})
用您的模板 shortId 替换“short-id-of-your-template”