繁体   English   中英

从对象解析名称并显示Angular Js

[英]Parse name from the object and display-Angular Js

我的对象(未解析和原始):

   $scope.result= {
        "id": 2360,        
        "subject": "Meeting Postponed Status",
        "message": "{\"name\":\"Riana\",\"status\":\"Postponed\",\"meeting\":\"Approval No 342\",\"postponedDate\":\"2015-06-24 18:30:00\",\"postponedTime\":\"13:02:57\"}",   
        "modifiedDate": "2015-06-29 17:09:59",
        "categoryId": 1,    
    }

我正在将$scope.result对象的属性message解析为

$scope.result=JSON.parse($scope.result.message); 输出$scope.result.message

$scope.result.message={"name":"Riana","status":"Postponed","meeting":"Approval No 342","postponedDate":"2015-06-24 18:30:00","postponedTime":"13:02:57"}

但是,如果我想绑定名称Riana ,则无法在HTMl中使用{{result.message.name}}进行尝试,但无法呈现该名称。 因为无法在控制器中执行解析,所以有没有办法在HTML中进行解析?

您需要 JSON.parse($scope.result.message) 分配$scope.result.message

例如

$scope.result.message = JSON.parse($scope.result.message);

这是JsFiddle链接

希望能帮助到你。

在声明之后。

$scope.result=JSON.parse($scope.result.message);

您的$ scope.result对象看起来像这样

Object {name: "Riana", status: "Postponed", meeting: "Approval No 342", postponedDate: "2015-06-24 18:30:00", postponedTime: "13:02:57"}

在HTML中,您应该这样使用

{{result.name}}

不像这个{{result.message.name}}

暂无
暂无

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

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