在使用Pbiviz开发自定义Power可视化时,什么可能导致$ is not a function错误?
当我想指定jquery插件时,就会出现这个问题。看起来是错误的库顺序,但输出文件有一个正确的。
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES5",
"sourceMap": true,
"out": "./.tmp/build/visual.js"
},
"files": [
".api/v1.7.0/PowerBI-visuals.d.ts",
"src/settings.ts",
"src/visual.ts",
"node_modules/@types/jquery/index.d.ts",
"node_modules/@types/datatables.net/index.d.ts",
"node_modules/@types/lodash/index.d.ts",
"node_modules/powerbi-visuals-utils-dataviewutils/lib/index.d.ts"
]
}pbiviz.json:
"externalJS": [
"node_modules/powerbi-visuals-utils-dataviewutils/lib/index.js",
"node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/lodash/lodash.min.js"
],package.json:
"dependencies": {
"@types/datatables.net": "^1.10.1",
"@types/jquery": "^2.0.48",
"@types/lodash": "^4.14.50",
"datatables.net": "^1.10.15",
"jquery": "^2.1.0",
"lodash": "^4.17.4",
"powerbi-visuals-utils-dataviewutils": "1.2.0"
},错误:
Uncaught TypeError: $ is not a function
at <anonymous>:14820:21
at <anonymous>:10387:3
at Window.<anonymous> (<anonymous>:10390:1)
at <anonymous>:25969:20
at Object.r [as injectJsCode] (visualhostcore.min.js:2)
at i.loadWithoutResourcePackage (visualsandbox.min.js:1)
at i.executeMessage (visualsandbox.min.js:1)
at i.onMessageReceived (visualsandbox.min.js:1)
at visualsandbox.min.js:1
at e.invokeHandler (visualhostcore.min.js:2)发布于 2017-08-11 08:16:29
问题是在沙箱中,所有自定义的可视化都在沙箱中工作,其中窗口对象是假窗口对象。
试着采取以下方式:
使用以下代码创建js文件:
var jQuery = typeof jQuery !== 'undefined'
? jQuery
: window['$'];并将此文件包含到pbiviz.json的pbiviz.json部分。但是将行放在“node_node/ jquery /dist/jquery.js”和"node_modules/datatables.net/js/jquery.dataTables.js",(所以,在jquery之后,但在jquery插件之前)
样本:https://github.com/Microsoft/powerbi-visuals-heatmap/blob/master/pbiviz.json#L24
https://stackoverflow.com/questions/45572355
复制相似问题