ExtJS 6 访问消息属性在存储同步的回调
ExtJS 6 access messageProperty in store sync's callback
我想在同步 ExtJS 网格后在 UI 中显示来自服务器的消息。以下是这是如何进行的
摘录:this.store.sync({
callback: function (records, operation, success) {
// messageProperty accessing code
},
success: function (batch, options) {
// messageProperty accessing code
},
failure: function (batch, options) {
}
});
下面是商店定义的一部分:
proxy: {
headers: { 'Accept': 'application/json' },
limitParam: undefined,
pageParam: undefined,
startParam: undefined,
paramsAsJson: false,
type: 'ajax',
// ...
reader: {
type: 'json',
rootProperty: 'Data',
messageProperty: 'Message'
},
// ...
},
下面是从服务器返回的一些数据(省略了数组内的数据:
{
"Data":[
],
"Message":"Success!"
}
该应用程序似乎在读取数据属性时没有问题(即我的网格工作正常),但我无法访问同步方法的回调或成功事件中的消息属性。这是错误消息:
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 存储的回调或成功函数中检索消息属性?
在 ExtJS 6 中,Sencha 已将默认值 keepRawData
更改为 false。如果将其更改回 true,则一切应再次按预期工作。Sencha文档告诉我们存在内存泄漏的可能性,但我还没有遇到过这样的问题。
您可能不必更改默认的 keepRawData 值在 ExtJS 6 中,您还可以使用以下方法从操作参数访问 messageProperty:
operation.error;
或
operation.getError();
唯一的问题是,如果成功参数为 true,则未设置 error 属性。在这种情况下,我想他们希望您使用 records 参数,因为无论如何,这是来自服务器的数据的位置。
相关文章:
- 架构师将存储同步到WebService
- 谷歌浏览器同步存储“获取”命令运行什么顺序
- 主干本地存储不使用良好的同步方法
- ExtJS 6 访问消息属性在存储同步的回调
- 如何同步记录而不是下载整个数据存储
- 如果在此期间没有记录更改,则在两秒钟后同步存储
- TypeError:对象不是函数(JavaScript Chrome存储同步)
- Jquery(Mobile)和phonegap存储模块未同步
- 正在等待本地存储的同步
- 骨干js远程存储同步错误restful
- 将本地存储认证令牌状态与视图同步
- EmberJS -保持模型与本地存储中的数据同步
- 如何在内容脚本中同步扩展本地存储
- Chrome扩展:等待存储.同步获取远程数据
- sencha touch同步存储性能问题
- 存储同步不会触发请求
- 如何在Google Chrome本地存储同步中设置变量键和值
- 本地存储-如何将Javascript对象与索引数据库同步
- 如何同步一个 GitHub 存储库和多个 Gist
- 我想在服务器响应之间加载本地存储(使java脚本代码同步)