ExtJs 6 - 通过success函数从返回的JSON中获取对象

时间:2017-06-02 02:10:15

标签: javascript extjs6 extjs6-classic

我正在使用record.erase删除记录,如果后端由于某种原因无法删除记录,我希望能够显示错误消息。我希望能够显示JSON中返回的消息。我假设我可以通过操作参数来做到这一点但是找不到方法。

那么如何从JSON访问“success”和“msg”?

控制器

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

1 个答案:

答案 0 :(得分:0)

自己想出来,非常简单 -

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