ExtJS 6访问messageProperty在商店同步的回调中 [英] ExtJS 6 access messageProperty in store sync's callback

查看:88
本文介绍了ExtJS 6访问messageProperty在商店同步的回调中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同步ExtJS网格后在UI中显示来自服务器的消息.这是一段摘录:

I want to display a message from my server in the UI after synchronizing an ExtJS grid. Here's an excerpt of how that goes:

this.store.sync({
        callback: function (records, operation, success) {
          // messageProperty accessing code
        },
        success: function (batch, options) {
          // messageProperty accessing code
        },
        failure: function (batch, options) {
        }
    });

这是商店定义的一部分:

Here's a piece of the store definition:

 proxy: {
    headers: { 'Accept': 'application/json' },
    limitParam: undefined,
    pageParam: undefined,
    startParam: undefined,
    paramsAsJson: false,
    type: 'ajax',        
    // ...
    reader: {
        type: 'json',
        rootProperty: 'Data',
        messageProperty: 'Message'
    },
    // ...
},

以下是一些从服务器返回的数据(省略了数组中的数据:

Here's some data that comes back from the server (omitted the data inside the array:

{
 "Data":[
 ],
 "Message":"Success!"
}

该应用程序似乎在读取data属性方面没有问题(即,我的网格正常工作),但是我无法在sync方法的回调或成功事件中访问message属性.这是错误消息:

The application doesn't seem to have issues with reading the data property (i.e. my grid works properly), but I'm not able to access the message property in either the callback or success event of the sync method. This is the error message:

Uncaught TypeError: Cannot read property 'Message' of undefined(…)

createAccessor: (function () {
    var re = /[\[\.]/;
    return function (expr) {
        var me = this,
            simple = me.getUseSimpleAccessors(),
            operatorIndex, result, current, parts, part, inExpr, isDot, isLeft, isRight, special, c, i, bracketed, len;
        if (!(expr || expr === 0)) {
            return;
        }
        if (typeof expr === 'function') {
            return expr;
        }
        if (!simple) {
            operatorIndex = String(expr).search(re);
        }
        if (simple === true || operatorIndex < 0) {
            result = function (raw) {
                return raw[expr];  <-------- This is where it goes wrong at some point
            };
        } 

如果我通过此代码调试,则原始变量有时会丢失其值,这会产生预期的未定义错误消息.我的问题是我如何能够在Ext 6商店的回调或成功函数中检索message属性?

If I debug through this code, at some point the raw variable loses its value, which gives the expected undefined error message. My question is how I could be able to retrieve the message property in the callback or success functions of an Ext 6 store?

推荐答案

在ExtJS 6中,Sencha更改了默认值

In ExtJS 6 Sencha has changed the default value of keepRawData to false. If you change it back to true, everything should work as expected again. Sencha docs tell us that there is a chance of a memory leak, but I have not yet experienced such an issue.

这篇关于ExtJS 6访问messageProperty在商店同步的回调中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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