gpt4 book ai didi

javascript - Grafana,使用外部库开发插件

转载 作者:行者123 更新时间:2023-11-29 20:57:35 26 4
gpt4 key购买 nike

大家好。我正在尝试为 Grafana 开发一个简单的插件。我已经设法导入了外部库,现在我对“使用它”感到震惊。

这是我在 domap_ctrl.js 中导入插件的方式:

System.register(['app/plugins/sdk', 'lodash','./datamaps'], function (_export, _context) {
var PanelCtrl, _, _createClass, panelDefaults, DoMapCtrl, Datamap;

然后我想触发数据图:

_createClass(DoMapCtrl, [
{
key: 'updateDoMap',
value: function updateDoMap() {
console.log("update: ",this.panel.foo);
if(document.getElementById('container')){
new Datamap({
element: document.getElementById("basic")
});
}
this.nextTickPromise = this.$timeout(this.updateDoMap.bind(this), 1000);
}
},
{
key: 'onRender',
value: function onRender() {
console.log("onRender",)
}
}
]);

但是我在将面板添加到仪表板时收到此错误:

TypeError: Datamap is not a constructor
at DoMapCtrl.updateDoMap (domap_ctrl.js:92)
at angular.js:20440
at i (angular.js:6362)
at angular.js:6642
(anonymous) @ angular.js:14700
(anonymous) @ angular.js:11142
(anonymous) @ angular.js:20443
i @ angular.js:6362
(anonymous) @ angular.js:6642
setTimeout (async)
c.defer @ angular.js:6640
o @ angular.js:20438
updateDoMap @ domap_ctrl.js:96
DoMapCtrl @ domap_ctrl.js:82
s @ angular.js:5040
d.instance @ angular.js:11000
f @ angular.js:9852
s @ angular.js:9174
(anonymous) @ angular.js:9039
v @ module.js:14
y @ module.js:38
(anonymous) @ module.js:44
Promise resolved (async)
link @ module.js:43
(anonymous) @ angular.js:1385
Ae @ angular.js:10545
f @ angular.js:9934
s @ angular.js:9174
f @ angular.js:9928
s @ angular.js:9174
(anonymous) @ angular.js:9039
(anonymous) @ angular.js:9430
r @ angular.js:9217
h @ angular.js:9984
(anonymous) @ angular.js:31499
r @ angular.js:18123
$digest @ angular.js:18261
$apply @ angular.js:18531
(anonymous) @ angular.js:27346
dispatch @ jquery.js:5206
g.handle @ jquery.js:5014
12:41:12.796 angular.js:14700 TypeError: Datamap is not a constructor
at DoMapCtrl.updateDoMap (domap_ctrl.js:92)
at angular.js:20440
at i (angular.js:6362)
at angular.js:6642 "Possibly unhandled rejection: {}"

我该如何解决?在此先感谢您的帮助。

最佳答案

即使不建议直接在 dist 文件夹中编辑 Grafana 插件(或不从 Typescript 转译)...

要导入您的库,您还需要修改提供依赖项注入(inject)的 setters 函数:

return {
setters: [
function (_lodash) {
// example for Lodash library
_ = _lodash.default;
}, function (_moment) {
// example for Moment.js library
moment = _moment.default;
}, function (datamap) {
// your library
Datamap = datamap;
}],
...

关于javascript - Grafana,使用外部库开发插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48500591/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com