如何在Yii2中禁用/覆盖依赖关系

编程入门 行业动态 更新时间:2024-10-28 18:34:43
本文介绍了如何在Yii2中禁用/覆盖依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

问题:

"kartik-v \ tree-manager"使用的"kartik-v \ yii2-dialog"会覆盖Sweetalert对话框/消息框.

The 'kartik-v\yii2-dialog' which is used by 'kartik-v\tree-manager' overrides Sweetalert dialog/message box.

为了使用SweetAlerts,如何禁用树视图管理器的依赖性'kartik-v \ yii2-dialog'?

How does one disable the treeview-manager's dependency 'kartik-v\yii2-dialog' in order to use SweetAlerts?

尝试:

'assetManager' => ['bundles' => [ 'kartik\dialog\DialogAsset' => ['js' => [],], ... ,

Sweetalert开始在网格中工作并确认事件,但是treemanager不再起作用(未捕获的ReferenceError:未定义KrajeeDialog)

Sweetalert starts working in grids and confirm events, but then treemanager no longer works (Uncaught ReferenceError: KrajeeDialog is not defined)

在图片中:

拥有:

想要:

任何输入将不胜感激.

更新:

这里是有效的替代代码,但是现在kartik \ yii2-dialog会随后加载并覆盖此代码:

Here is the override code, which has worked, but now kartik\yii2-dialog is loaded afterward and overrides this:

yii.confirm = function(message, okCallback, cancelCallback) { if (message.constructor === Array) { swal( { html: true, // SweetAlert1 title: message[0], text: message[1], //html: message[1], // SweetAlert2 //confirmButtonColor: '#E80000', confirmButtonColor: message[3], //type: 'warning', type: message[2], showCancelButton: true, cancelButtonText: 'Avbryt', closeOnConfirm: true, allowOutsideClick: true, buttonsStyling: false, }, okCallback ); } else { swal( { html: true, // SweetAlert1 title: message, type: 'warning', showCancelButton: true, cancelButtonText: 'Avbryt', closeOnConfirm: true, allowOutsideClick: true, buttonsStyling: false, }, okCallback ); } }; confirm = function(message, okCallback, cancelCallback) { if (message.constructor === Array) { swal( { html: true, // SweetAlert 1 title: message[0], text: message[1], //html: message[1], // SweetAlert2 //confirmButtonColor: '#E80000', confirmButtonColor: message[3], //type: 'warning', type: message[2], showCancelButton: true, cancelButtonText: 'Avbryt', closeOnConfirm: true, allowOutsideClick: true, buttonsStyling: false, }, okCallback ); } else { swal( { html: true, // SweetAlert 1 title: message, type: 'warning', showCancelButton: true, cancelButtonText: 'Avbryt', closeOnConfirm: true, allowOutsideClick: true, }, okCallback ); } }; yii.alert = function(message, okCallback, cancelCallback) { swal( { title: message, type: 'warning', showCancelButton: false, closeOnConfirm: true, allowOutsideClick: false, buttonsStyling: false, }, okCallback ); }; alert = function(message, okCallback, cancelCallback) { swal( { title: message, type: 'warning', showCancelButton: false, closeOnConfirm: true, allowOutsideClick: false, buttonsStyling: false, }, okCallback ); };

推荐答案

尽管TreeView中的krajeeDialogSettings提供了一个选项,可以通过使用来控制yii2-dialog

Although there is an option provided as krajeeDialogSettings in TreeView which controls the yii2-dialog via using,

'krajeeDialogSettings' => ['overrideYiiConfirm' => true, 'useNative' => true],

根据文档,它应该可以工作,但是对我来说,它不起作用,并且yii2-dialog总是会覆盖Sweetalert确认,我想从树状视图中排除提示或yii2-dialog并删除依赖关系不是那么直接,因为调用是嵌套和集成在Treeview脚本中的.

According to the docs it should work but for me, it didn't worked, and the yii2-dialog always overrode the sweetalert confirm, I wanted to rule out the prompt or the yii2-dialog from the treeview and for that removing the dependency is not that straight forward because the calls are nested and integrated in the Treeview script.

因此,我必须重写加载TreeView小部件的krajeeDialog.confirm,以便每当调用krajeeDialog.confirm时,都会调用我的自定义确认对话框.

So, I had to override the krajeeDialog.confirm where i was loading the TreeView widget so that whenever the krajeeDialog.confirm is called my custom confirm dialog would be called.

只需在要加载TreeView小部件的视图顶部添加以下内容.

Just add the below on the top of the view where you are loading the TreeView widget.

<?php $js = <<< JS krajeeDialog.confirm = function (message, callback) { swal({ title: message, type: "warning", showCancelButton: true, closeOnConfirm: true, allowOutsideClick: true }, callback); } JS; $this->registerJs($js, yii\web\view::POS_READY);

尽管我不喜欢双重方法,但这是唯一对我有用的方法,也许其他人可以发布更好的解决方案.

Although i didnt like the dual approach but that was the only one that worked for me, maybe someone else could post a better solution.

更多推荐

如何在Yii2中禁用/覆盖依赖关系

本文发布于:2023-08-03 15:31:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!