简体   繁体   English

在 Symfony 4 中使用 WebPack Encore 定义后无法识别 JavaScript 对象

[英]JavaScript Object is not recognized after defined using WebPack Encore in Symfony 4

I am trying to include BootstrapDialog in a Symfony 4 project using WebPack Encore.我正在尝试使用 WebPack Encore 在 Symfony 4 项目中包含 BootstrapDialog。

First, I copied the Bootstrap Dialog JS file to the JS folder where all other JS files reside.首先,我将 Bootstrap Dialog JS 文件复制到所有其他 JS 文件所在的 JS 文件夹中。

Second, I have done this in app.js file:其次,我在 app.js 文件中做了这个:

require('./bootstrap-dialog');

global.$ = global.jQuery = $;

alert(BootstrapDialog);

Third I have added this inside bootstrap dialog JS file.第三,我在引导对话框 JS 文件中添加了这个。

alert(BootstrapDialog);

Notice the alert in app.js and the alert in the bootstrap dialog js file.注意 app.js 中的警报和引导对话框 js 文件中的警报。

The alert in the bootstrap dialog js file shows the BootstrapDialog function body, however, the alert in app.js caused this to be displayed in browser console window:引导对话框 js 文件中的警报显示了 BootstrapDialog 函数体,但是,app.js 中的警报导致它显示在浏览器控制台窗口中:

 ReferenceError: BootstrapDialog is not defined

How can I make BootstrapDialog function to be accesible from outside its own JS file?如何使 BootstrapDialog 函数可以从它自己的 JS 文件之外访问?

Regards Jaime问候海梅

You can use bootbox ( http://bootboxjs.com/ )您可以使用引导箱( http://bootboxjs.com/

In app.js or other, you write bootbox = require('bootbox');在 app.js 或其他,你写bootbox = require('bootbox');

That's all就这样

You can use it :你可以使用它:

  • bootbox.alert("Your message here…") bootbox.alert("你的消息在这里...")
  • bootbox.confirm("Are you sure?", function(result){ /* your callback code */ }) bootbox.confirm("Are you sure?", function(result){ /* 你的回调代码 */ })

... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM