FastAdmin 插件管理中的 json 从哪里来的?

FastAdmin 插件管理中的 json 从哪里来的?

在 FastAdmin 插件管理中有段这样的代码,可能小伙伴有一个疑问 json 这个参数从哪里传入的?


            table.on('load-success.bs.table', function (e, json) {
                if (json && typeof json.category != 'undefined' && $(".nav-category li").size() == 2) {
                    $.each(json.category, function (i, j) {
                        $("<li><a href='javascript:;' data-id='" + j.id + "'>" + j.name + "</a></li>").insertBefore($(".nav-category li:last"));
                    });
                }
            });

的确,这里没有看到,那他是从哪里来的呢?
答案如下:

                responseHandler: function (res) {
                    $.each(res.rows, function (i, j) {
                        console.log(i);
                        j.addon = typeof Config.addons[j.name] != 'undefined' ? Config.addons[j.name] : null;
                    });
                    return res;
                },

什么? 名字不一样?是的,他的参数并不是使用全局传过来的。

这得回到 bootstrap-table 代码中查看。

        data = calculateObjectValue(this.options, this.options.queryParams, [params], data);

        $.extend(data, query || {});

        // false to stop request
        if (data === false) {
            return;
        }

        if (!silent) {
            this.$tableLoading.show();
        }
        request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
            type: this.options.method,
            url:  url || this.options.url,
            data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
                JSON.stringify(data) : data,
            cache: this.options.cache,
            contentType: this.options.contentType,
            dataType: this.options.dataType,
            success: function (res) {
                res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);

                that.load(res);
                that.trigger('load-success', res);
                if (!silent) that.$tableLoading.hide();
            },
            error: function (res) {
                that.trigger('load-error', res.status, res);
                if (!silent) that.$tableLoading.hide();
            }
        });

posted on 2020-09-24 21:10  建伟F4nniu  阅读(349)  评论(0)    收藏  举报

导航