2017-06-02 42 views
0

我正在使用record.erase來刪除一條記錄,並且如果後端無法刪除記錄,我希望能夠顯示錯誤消息原因。我希望能夠顯示在JSON中返回的msg。我想我可以通過操作參數來做到這一點,但一直沒有找到辦法。ExtJs 6 - 通過成功函數從返回的JSON中獲取對象

那麼我怎樣才能從JSON訪問「成功」和「味精」呢?

控制器

if (record.data.privatePwdsCount === 0) 
     Ext.Msg.confirm("Delete", "Are you sure you want to delete this group?", function (id, value) { 
      if (id === 'yes') {   
       record.erase({ 
        success: function (record, operation) { 
         // check if 'success' is true or false 
         // if true = do nothing 
         // if false = display error msg to user 
        } 
       });     
      } 
     }); 
    else { 
     Ext.Msg.alert("Cannot Delete Group", "This group has existing passwords, delete the passwords first to continue"); 
    } 

JSON

"{"success":true,"msg":"Private Group 20 was deleted."}" 

回答

0

想通了我自己,真的很簡單 -

var jsonResponse = Ext.decode(operation.getResponse().responseText); 
var success = jsonResponse.success; 
var msg = jsonResponse.msg;