Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Yii2中禁用/覆盖依赖项_Javascript_Yii2_Assets_Sweetalert_Kartik V - Fatal编程技术网

Javascript 如何在Yii2中禁用/覆盖依赖项

Javascript 如何在Yii2中禁用/覆盖依赖项,javascript,yii2,assets,sweetalert,kartik-v,Javascript,Yii2,Assets,Sweetalert,Kartik V,问题: 由“kartik-v\tree manager”使用的“kartik-v\yii2对话框”覆盖Sweetalert对话框/消息框 如何禁用treeview管理器的依赖项“kartik-v\yii2对话框”以使用SweetAlerts 尝试过了: 'assetManager' => ['bundles' => [ 'kartik\dialog\DialogAsset' => ['js' => [],], ... , Sweetalert开始在网格中工作并确认事件,

问题

由“kartik-v\tree manager”使用的“kartik-v\yii2对话框”覆盖Sweetalert对话框/消息框

如何禁用treeview管理器的依赖项“kartik-v\yii2对话框”以使用SweetAlerts

尝试过了

'assetManager' => ['bundles' => [ 'kartik\dialog\DialogAsset' => ['js' => [],], ... ,
Sweetalert开始在网格中工作并确认事件,但treemanager不再工作(未捕获引用错误:未定义KrajeeDialog)

图片:

拥有:

想要:

如有任何意见,将不胜感激

更新:

下面是覆盖代码,该代码已经工作,但现在kartik\yii2对话框随后被加载并覆盖:

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
,它通过使用

'krajeeDialogSettings' => ['overrideYiiConfirm' => true, 'useNative' => true],
根据文档,它应该可以工作,但对我来说,它不起作用,
yii2对话框
总是覆盖sweetalert确认,我想从treeview中排除提示或yii2对话框,因此删除依赖项并不是那么简单,因为调用嵌套并集成在treeview脚本中

因此,我必须覆盖
krajeeDialog.confirm
我加载
TreeView
小部件的位置,以便无论何时调用
krajeeDialog.confirm
我的自定义确认对话框

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

<?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);

您使用的是哪个版本的Sweet Alert?1或2 Weet alert 1 thank you@MuhammadOmerAslami在我的一个项目中也使用了sweetalert 1,我正在使用TreeView,但我没有体验到你所说的。您能展示一下您的代码吗?您是如何覆盖GridView的默认Yii确认对话框的?我这里说的是Sweetalert开始在网格中工作并确认事件,但是treemanager不再工作(未捕获引用错误:未定义KrajeeDialog),尽管treeview确实显示了默认的yii2对话框小部件确认而不是sweetalert,首先,您需要添加代码,并明确在treview中显示kartik/yi2对话框的提示,或者您收到错误消息?在kartik\dialog\dialog中有两个相关属性:$OverrideIIConfirm和$useNative,但不清楚如何全局设置这些属性。对话框小部件永远不会被其他小部件直接或间接使用。已在配置文件中尝试过:“dialog'=>['class'=>'\kartik\dialog\dialog”,“useNative'=>true”,“OverrideIIConfirm'=>false,]”,但没有效果。如果在供应商文件中修改了属性,那么一切都可以正常工作,但这不是一个选项@穆罕默德·默拉斯拉姆