Extjs 存储加载成功处理程序没有被触发 [英] Extjs store load success handler not getting fired

查看:23
本文介绍了Extjs 存储加载成功处理程序没有被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储加载方法,它通过 ajax 请求返回数据.我可以看到正在使用 Firebug 返回数据,但没有调用我的成功处理程序:

I have a store load method which returns data via an ajax request. I can see that the data is being returned using Firebug, but my success handler is not getting called:

    this.getCategoriesStore().load({params:{'id':d.data.category_id}}, {
        success: function(category) {
            console.log("Category: " + category.get('name'));
        },
        error: function(e) {
            console.log(e);
        }
    });

我正在返回一个成功参数以及数据:

I am returning a success parameter, along with the data:

{"success":true,"categories":{"id":5,"name":"Frying","section_id":2}}

是不是我做错了什么?

推荐答案

好吧,我想你正在寻找这个:

Well I suppose you are looking for this:

store.load({
    params:{'id':d.data.category_id},
    scope: this,
    callback: function(records, operation, success) {
        if (success) {
            console.log("Category: " + category.get('name'));
        } else {
            console.log('error');
        }
    }
});

API 您的附加参数也可以放在那里.但是 ExtJS 经常使用 config 对象来包装东西.

It is not that obvious in the API that your additional params can be placed there too. But ExtJS often uses the config objects to wrap things up.

编辑以回答评论:

简短的回答是:

现在是更长的版本:对于商店,您可以直接提供匿名(或具体)回调或注册事件.在您的情况下,两者都将起作用.

Now the longer version: In case of the store it is up to you to directly provide anonymous (or concrete) callbacks or register events. Both will work the same in your situation here.

但是你只能有一个回调,而你可以有很多事件.在进一步的场景中,您会发现事件更适合的情况或事件是唯一的方法.当你在听的时候,情况总是如此.这里有一些注意事项:

But you can only have one callback while you can have many events. In further scenarios you will find situations where events fits much better or where events are the only way at all. That will always be the case when you are listening. Here are some notes on that:

  • 当您只需要回调一次时,请使用 { single: true } 属性.示例: store.on('load', function(s) {/* do something*/}, scope, { single: true }) 监听器在调用后会被移除.这是使用匿名函数的必要原因,无法删除.
  • 利用mon() 在大多数情况下,您直接在类定义中绑定侦听器以确保侦听器与类的实例一起销毁.
  • make use of the { single: true } property when you just need a callback once. Example: store.on('load', function(s) { /* do something*/ }, scope, { single: true }) The listener will be removed after it was called. This is needed cause of the use of a anonymous function, that cannot be removed.
  • make use of mon() in most cases where you bind listeners directly in class-definitions to ensure the listeners get destroyed along with the instance of the class.

两者都可以节省您的浏览器内存.

Both will save you browser memory.

这篇关于Extjs 存储加载成功处理程序没有被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆