【问题标题】:ExtJS Callback Functions ExampleExtJS 回调函数示例
【发布时间】:2022-05-07 22:06:35
【问题描述】:

我是 ExtJs 的新手,我正在努力弄清楚如何在 ExtJs 中使用回调函数。我使用的 ExtJs 版本是 4.2.1 基本上我想链接两个函数的执行:

func1: 函数() { }

func2: 函数() { }

这样 func2() 仅在 func1() 完成后开始执行。

从我目前阅读的内容来看,我需要使用回调函数,但对于我来说,我无法得到它。

这是我的代码:

filter: function (filters, value) {

    if (Ext.isString(filters)) {
        filters = {
            property: filters,
            value: value
        };
    }

    var me = this,
        decoded = me.decodeFilters(filters),
        i = 0,
        length = decoded.length;

    for (; i < length; i++) {
        me.filters.replace(decoded[i]);
    }

    Ext.Array.each(me.filters.items, function (filter) {
        Ext.Object.each(me.tree.nodeHash, function (key, node) {
            if (filter.filterFn) {
                if (!filter.filterFn(node)) node.remove();
            } else {
                if (node.data[filter.property] != filter.value) node.remove();
            }
        });
    });
    me.hasFilter = true;

    console.log(me);
},

clearFilter: function() {
    var me = this;
    me.filters.clear();
    me.hasFilter = false;
    me.load();
},

isFiltered: function() {
    return this.hasFilter;
},


filterNavAdminSTByUserName: function (nameValue) {

    this.clearFilter();

    this.filter([{
        property: 'userName',
        value: nameValue
    }]);

}

我的问题是 this.filter() 在 this.clearFilter(); 之前执行如何强制 this.filter() 仅在 this.clearFilter() 完成后执行?

提前致谢!

【问题讨论】:

  • 你的问题有点含糊。 func1 是异步方法吗?
  • 您不能将方法设置为异步。我问func1 做任何异步的事情吗?通常是 ajax 请求。
  • 我不知道您可以在 ExtJs 4.2.1 中将方法设置为异步。据我所知(您可以猜到的知识有限)默认情况下,所有方法都是异步的。我该如何设置? func1 和 func2 都需要同步吗?还是只是 func1?

标签: extjs4


【解决方案1】:

经过一番深思熟虑,我终于弄清楚了回调函数的工作原理。 所以这里是解决方案:

clearAndFilter: function (nameValue) {
    var me = this;
    me.filters.clear();
    me.hasFilter = false;
    me.load({
        scope: me,
        callback: function () {
            // filter the store 
            me.filter('userName', nameValue);
        }

    });
},

filterNavAdminSTByUserName: function (nameValue) {
    this.clearAndFilter(nameValue);
}

很高兴回答我第一次在这里发帖!

【讨论】:

    猜你喜欢
    • 2014-04-21
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 2023-04-06
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多