简体   繁体   English

如何访问数组中的元素

[英]How to access to element in array

I am trying to figure out how to access the value of message "Meeting 9943...is not found or has expired"我试图弄清楚如何访问消息“会议 9943 ...未找到或已过期”的值

I tried:我试过了:

                if (response.data.status == 404) {
                    angular.element(document.getElementById("msg")).css("color", "red");
                    $scope.msg = response.data.message.message; <- this show undefined
                    console.log("Status Code= " + response.data.status + ", Status Text= " + response.data.message);
                    return false;
                }

手表

What is the correct method to access the value of response.data.message.message?访问 response.data.message.message 值的正确方法是什么?

Thank you for your help谢谢您的帮助

The value of the message is a string, you need to parse it with:消息的值是一个字符串,你需要解析它:

JSON.parse(response.data.message)

And after that, you can access to the property message inside the object.之后,您可以访问 object 内部的属性消息。

That is the correct syntax, are you sure this debug snapshot is for the object you are getting the error on?这是正确的语法,您确定此调试快照适用于您遇到错误的 object 吗?

Try尝试

$scope.msg = response.data.message && response.data.message.message;

this will not try and access the message for cases where the parent message object doesn't exist.对于父消息 object 不存在的情况,这不会尝试访问该消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM