2016-02-05 50 views
2

我想在同步ExtJS網格後在UI中顯示來自我的服務器的消息。下面是如何繼續下去的摘錄:ExtJS 6訪問商店同步回調中​​的消息

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!" 
} 

該應用程序似乎沒有閱讀數據屬性(即我的網格工作正常)的問題,但我無法訪問消息屬性的回調或成功事件的t他同步方法。這是錯誤消息:

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商店的回調函數或成功函數中檢索消息屬性?

回答

1

在ExtJS 6中,Sencha已將默認值keepRawData更改爲false。如果您將其更改爲true,則應再次按預期工作。 Sencha文檔告訴我們存在內存泄漏的可能性,但我還沒有遇到過這樣的問題。

+0

工作。在回調委託中,我現在可以使用以下代碼訪問消息屬性:this.reader.rawData.Message。 – hbulens