简体   繁体   中英

Accessing Nested JSON with AngularJS

I'm trying to pull data from Behance.net and I'm running into two issues when I try to get the information.

The first issue is trying to pull the description of the project. I can get the information by calling ng-bind="project.description" but the formatting (paragraph returns) is not present, so I'm trying to pull the formatted description.

Here is the html:

<div class="col-sm-6">
    <h3 ng-bind="project.name"></h3>
    <p ng-bind="project.modules.text"></p>

    <h4><i class="fa fa-tags success"></i> Tags</h4>
    <div class="row">
      <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div class="pull-left label label-info" style="margin-right:5px; margin-bottom:10px;"
              ng-repeat="tag in project.tags" ng-bind="tag"></div>
      </div>
    </div>

Here is the JSON data Behance is showing:

angular.callbacks._0({
    "project": {
    ....
         "modules": [{
            "id": 111549713,
            "type": "text",
            "text": "This is the description of the project I am trying to get"

My second issue I'm guessing is the same as the first, but here it is.

<p style="margin-top:10px;" ng-bind="user.sections.About"></p>

and the JSON file:

angular.callbacks._1({
    "user": {
       "sections": {
            "About Me": Description used on the behance website that I am trying to display

I can pull any information except these two instances. Any help would be greatly appreciated.

First issue:

project.modules is an array, so try this instead:

<p ng-bind="project.modules[0].text"></p>

Second issue:

As the property 'About Me' contains a space you will need to use the bracket notation to access it:

<p style="margin-top:10px;" ng-bind="user.sections['About Me']"></p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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