【问题标题】:Parse name from the object and display-Angular Js从对象解析名称并显示-Angular Js
【发布时间】:2015-06-29 12:15:20
【问题描述】:

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

   $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,因为我无法在控制器中进行解析?

【问题讨论】:

  • 你能告诉我们你的html代码吗?
  • 就像这样 {{result.message.name}}
  • 你从 {{result}} 和 {{result.message}} 得到什么
  • 对于 {{result}}:{“主题”:“会议推迟状态”,“消息”:“{\”name\”:\“RianaMinny\”,\“status\”: \"延期\",\"会议\":\"342号矿区审批\",\"延期日期\":\"2015-06-24 18:30:00\",\"延期时间\" :\"13:02:57\"}", "modifiedDate": "2015-06-29 17:09:59", "categoryId": 1 }
  • 和 {{result.message}} :{"name":"Riana","status":"Postponed","meeting":"Approval No 342","postponedDate":"2015 -06-24 18:30:00","postponedTime":"13:02:57"}

标签: javascript json angularjs scope


【解决方案1】:

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

例如

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

这是JsFiddle link

希望对你有帮助。

【讨论】:

    【解决方案2】:

    在此声明之后。

    $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}}

    【讨论】:

    • @Riaj Khan 名字在消息对象中
    • 你想用名称进行双向数据绑定吗?
    猜你喜欢
    • 2015-09-27
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    相关资源
    最近更新 更多