【问题标题】:Magento 2 : Display Loader While Ajax call on Column row action?Magento 2:Ajax 调用列行操作时显示加载器?
【发布时间】:2019-01-17 18:04:07
【问题描述】:

网格 xml 列:

<column name='actions' class='My\Test\Ui\Component\Listing\Columns\Feeds\AdvancedActions'> 
    <argument name='data' xsi:type='array'> 
        <item name='config' xsi:type='array'>
            <item name='component' xsi:type='string'>My_Test/js/grid/columns/actions</item> 
            <item name='dataType' xsi:type='string'>text</item> 
            <item name='label' xsi:type='string' translate='true'>Actions</item> 
            <item name='sortOrder' xsi:type='number'>90</item> 
        </item>
    </argument>
</column>

Actions.js

define(
    [
    'jquery',
    'underscore',
    'mageUtils',
    'uiRegistry',
    'Magento_Ui/js/grid/columns/actions',
    'Magento_Ui/js/modal/confirm'
    ], function ($, _, utils, registry, Column, confirm) {
        'use strict';
    return Column.extend(
        {

            /**
             * Applies specified action.
             *
             * @param   {String} actionIndex - Actions' identifier.
             * @param   {Number} rowIndex - Index of a row.
             * @returns {ActionsColumn} Chainable.
             */
            applyAction: function (actionIndex, rowIndex) {
                var action = this.getAction(rowIndex, actionIndex),
                callback = this._getCallback(action);

                if (action.confirm) {
                    this._confirm(action, callback);
                } else if (action.popup) {
                    this._popup(action, callback);
                } else {
                    callback();
                }

                return this;
            },


           _popup: function (action, callback) {
                var popupData = action.popup;
                var dataType = popupData.type;

                //Start loader
                var body = $('body').loader();
                body.loader('show');

                if (popupData.file !== undefined && popupData.file !== '') {
                    $.ajax(
                        {
                            url: popupData.file,
                            async: false,
                            dataType: "text",
                            type: 'GET',
                            showLoader: true, //use for display loader
                            success: function (data) {
                                popupData.message = data;
                            }
                        }
                    );
                }
                //Stop loader
                body.loader('hide');
            },
});

使用 showLoader: truevar body = $('body').loader(); body.loader('show'); 但无法在 ajax 请求时启动加载程序。

需要在 ajax 调用期间启动加载程序的替代方法。

【问题讨论】:

    标签: magento2 magento2.2


    【解决方案1】:

    我遇到了同样的问题。就我而言,我需要加载 'jquery/ui' 依赖项。

    define(
        [
        'jquery',
        ...
        'jquery/ui'
    

    【讨论】:

    • 尝试清除缓存,并将jquery/ui作为最后一个依赖。
    • 试过但同样的问题。
    【解决方案2】:

    请查看以下可能有帮助的代码。

    define([
        'jquery',
        'Magento_Checkout/js/model/full-screen-loader',
    ], function ($,fullScreenLoader
    ) {
        //Start Loader
        fullScreenLoader.startLoader();
        //Your AJax COde here
    
        //Stop Loader
        fullScreenLoader.stopLoader();
    });
    

    【讨论】:

      【解决方案3】:

      只需在末尾添加loader 依赖即可:

      define([
          'jquery',
          ...
          'loader'
      ]
      

      showLoader: truevar body = $('body'); body.loader('hide'); 将开始工作。

      【讨论】:

        【解决方案4】:

        试试$('body').trigger('processStart') & $('body').trigger('processStop')

        【讨论】:

          猜你喜欢
          • 2017-03-25
          • 1970-01-01
          • 1970-01-01
          • 2012-03-28
          • 2012-03-01
          • 2013-07-22
          • 1970-01-01
          • 1970-01-01
          • 2011-06-08
          相关资源
          最近更新 更多